A
Arild Bakken
Hi,
I'm facing a problem where using the System.Data.OleDb library to read
binary data from a SQL Server 2000 database. The sample code:
OleDbConnection objConn = new OleDbConnection("Provider=SQLOLEDB;Data
Source=SQLSERVERNAME;Initial Catalog=pubs;Integrated Security=SSPI");
objConn.Open();
OleDbCommand objCmd = new OleDbCommand("SELECT logo, pr_info FROM pub_info
WHERE pub_id = ?", objConn);
objCmd.CommandType = CommandType.Text;
objCmd.Parameters.Add("@pubid", 736);
OleDbDataReader objReader = objCmd.ExecuteReader();
objReader.Read();
objReader.Close();
objCmd.Dispose();
objConn.Close();
objConn.Dispose();
Running this in a loop, say 2000 times you'll see that the memory of the
process keeps growing and growing (on my computer it passed 128MB). The data
retrieved is pretty small (643 byte logo and 64KB info) and running the same
type of code against a database with, say a 5MB word document will
dramatically eat up the memory. I tested that, and the process ate 10MB of
memory every second (it carried out two requests per second) so it would
seem the entire blob of data retrieved was leaked...
If, however, I update the code to use the System.Data.SqlClient library
instead with its SqlConnection, SqlCommand and SqlDataReader objects (and
modify the select statement and connection string) then the leak is gone.
Does anyone have any idea what I'm missing here? Now, I could change all my
code to use SqlClient instead, but I really can't believe that there is such
a tremendous leak in the OleDb libraries of .NET nor in the OleDb native
libraries so I'm guessing I've missed something on the Close() / Dispose()
requirements - and if that's the case I might end up with the same problem
with the SqlClient libraries later...
BTW - this is .NET 1.1 and sample has been run on Win2K SP4 with all
patches, and on WinXP SP1 with all patches.
Any tips as very welcome.
Regards,
Arild
I'm facing a problem where using the System.Data.OleDb library to read
binary data from a SQL Server 2000 database. The sample code:
OleDbConnection objConn = new OleDbConnection("Provider=SQLOLEDB;Data
Source=SQLSERVERNAME;Initial Catalog=pubs;Integrated Security=SSPI");
objConn.Open();
OleDbCommand objCmd = new OleDbCommand("SELECT logo, pr_info FROM pub_info
WHERE pub_id = ?", objConn);
objCmd.CommandType = CommandType.Text;
objCmd.Parameters.Add("@pubid", 736);
OleDbDataReader objReader = objCmd.ExecuteReader();
objReader.Read();
objReader.Close();
objCmd.Dispose();
objConn.Close();
objConn.Dispose();
Running this in a loop, say 2000 times you'll see that the memory of the
process keeps growing and growing (on my computer it passed 128MB). The data
retrieved is pretty small (643 byte logo and 64KB info) and running the same
type of code against a database with, say a 5MB word document will
dramatically eat up the memory. I tested that, and the process ate 10MB of
memory every second (it carried out two requests per second) so it would
seem the entire blob of data retrieved was leaked...
If, however, I update the code to use the System.Data.SqlClient library
instead with its SqlConnection, SqlCommand and SqlDataReader objects (and
modify the select statement and connection string) then the leak is gone.
Does anyone have any idea what I'm missing here? Now, I could change all my
code to use SqlClient instead, but I really can't believe that there is such
a tremendous leak in the OleDb libraries of .NET nor in the OleDb native
libraries so I'm guessing I've missed something on the Close() / Dispose()
requirements - and if that's the case I might end up with the same problem
with the SqlClient libraries later...
BTW - this is .NET 1.1 and sample has been run on Win2K SP4 with all
patches, and on WinXP SP1 with all patches.
Any tips as very welcome.
Regards,
Arild