C
Colin Sewell
Maybe there's something I'm doing wrong here. I'm open to any
suggestions.
I'll see if I can explain this clearly...
I have a C# application that runs 24x7 collecting data from some
source and storing the data in a Microsoft Access database. The
problem is, every time it stores the data using a call to
OleDbCommand.ExecuteNonQuery(), the applications memory usage grows.
After a few days, the application has consumed most of the systems'
virtual memory and grows more and more sluggish and unresponsive. The
only solution right now is to restart the application every couple of
days.
Since the app uses one database and stores the same database fields
with only the data changing, I set up everything at the start of the
program. After that, as data comes in, only the stored data parameter
values change.
The first thing I do is open the MS Access database using an
OleDbConnection with a Microsoft.Jet.OLEDB.4.0 provider. I then create
a OleDbCommand with a command string that basically consists of
"INSERT INTO table (field1, field2...) VALUES (?,?...)". Next I use
OleDbCommand.Parameters.Add to add OleDbParameter data parameters that
correspond to each field to the OleDbCommand, with the proper datatype
for each field. Lastly I set the OleDbConnection in the OleDbCommand.
As the data is collected I go through each OleDbParameter and set its
Value to either the data collected or DBNull.Value if the data is
missing. Then I call OleDbCommand.ExecuteNonQuery to actually store
the data. That occurs successfully, but the virtual memory alllocation
goes up and up each time the data is stored. I monitor the memory
usage with Sysinternals ProcExp, and if I comment out the call to
actually store the data, the memory usage remains constant.
So am I doing something wrong, or is there a memory leak in
OleDbCommand.ExecuteNonQuery?
suggestions.
I'll see if I can explain this clearly...
I have a C# application that runs 24x7 collecting data from some
source and storing the data in a Microsoft Access database. The
problem is, every time it stores the data using a call to
OleDbCommand.ExecuteNonQuery(), the applications memory usage grows.
After a few days, the application has consumed most of the systems'
virtual memory and grows more and more sluggish and unresponsive. The
only solution right now is to restart the application every couple of
days.
Since the app uses one database and stores the same database fields
with only the data changing, I set up everything at the start of the
program. After that, as data comes in, only the stored data parameter
values change.
The first thing I do is open the MS Access database using an
OleDbConnection with a Microsoft.Jet.OLEDB.4.0 provider. I then create
a OleDbCommand with a command string that basically consists of
"INSERT INTO table (field1, field2...) VALUES (?,?...)". Next I use
OleDbCommand.Parameters.Add to add OleDbParameter data parameters that
correspond to each field to the OleDbCommand, with the proper datatype
for each field. Lastly I set the OleDbConnection in the OleDbCommand.
As the data is collected I go through each OleDbParameter and set its
Value to either the data collected or DBNull.Value if the data is
missing. Then I call OleDbCommand.ExecuteNonQuery to actually store
the data. That occurs successfully, but the virtual memory alllocation
goes up and up each time the data is stored. I monitor the memory
usage with Sysinternals ProcExp, and if I comment out the call to
actually store the data, the memory usage remains constant.
So am I doing something wrong, or is there a memory leak in
OleDbCommand.ExecuteNonQuery?