当前位置: 动力学知识库 > 问答 > 编程问答 >

C# + SQL Select + dataset + dataadapter = out of memory

问题描述:

I'm currently trying to use C# to read through an SQL DB. To do so, I use OleDB with a select statement. This goes into a dataset, which then populates a data adapter. I then iterate through each row and calculate stuff.

First of all, I feel like there's a better/more efficient way of doing this because I NEVER actually write back to the SQL DB. I just calculate based on what I'm selecting.

Anyways, past a certain point I get out of memory errors and/or an error from Ssms.exe saying "a new guard page for the stack cannot be created."

From the other questions I've seen, I need to use DataReader but I can't seem to get it to work the same way as the data adapter (which I suppose isn't that surprising).

The code I have now:

OleDbConnection myConn = new OleDbConnection(@"SQLDB connection string here");

OleDbCommand cmd = new OleDbCommand();

cmd.CommandText = <selectstatement here>

cmd.Connection = myConn;

cmd.CommandTimeout = 0;

OleDbDataAdapter da = new OleDbDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

myConn.Close();


 foreach (DataTable table in ds.Tables)

{

foreach (DataRow dr in table.Rows)

{

//do stuff

I guess my question is twofold, like I said above. One would DataReader solve my problem and allow me to iterate through the data, and two how do I adapt the first code snippet above to support that?

Also, since I've seen it elsewhere, I'm using x64 on the application.

分享给朋友:
您可能感兴趣的文章:
随机阅读: