如果行数约为5811753,则将数据从数据库访问到数据集中 [英] Access data from database into dataset if rows are about 5811753

查看:58
本文介绍了如果行数约为5811753,则将数据从数据库访问到数据集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的连接字符串-------

My connection string -------

<appSettings>
        <add key="Connstr" value="Server=192.168.1.6\SQLExpress;database=Mydatabase;uid=usename;pwd=password;"/>
    </appSettings>



//显示超时错误,如何避免并设置为无限.

第二个问题:-



//Showing timeout error,how can i avoid it and set to infinite.

2nd question:-

string sqlquery = "Select * from tablename";
           SqlDataAdapter DA = new SqlDataAdapter(sqlquery, Connstr);
           DataSet DS = new DataSet();
           DA.Fill(DS);


//显示错误-


//showing error-

Exception of type ''System.OutOfMemoryException'' was thrown.


//在我的数据库中,有5811753个row.so,请告诉我如何避免上述错误,从而访问数据集中的行.


//In my database there are 5811753 rows.so tell me how can i access rows in dataset,by avoiding above error.

推荐答案

<appSettings>
        <add key="Connstr" value="Server=192.168.1.6\SQLExpress;database=Mydatabase;timeout=100000;uid=usename;pwd=password;"/>
    </appSettings>


祝您编程愉快!
:)


Happy coding!
:)




请参阅下面的链接,它可能会帮助您解决问题.由于一次获取大量数据而发生错误.最好在一定间隔内获取记录.您可以使用分页.可能会解决您的问题.

http://social.msdn.microsoft.com/论坛/en-US/csharpgeneral/thread/60432190-8b83-4f9e-a21f-4c830a5005fc [ http://msdn.microsoft.com/en-us/library/tx1c9c2f%28v = vs.80%29.aspx [ ^ ]
http://www.dotnetspider.com/forum/234222-System. OutOfMemoryException-thrown-case-huge-data.aspx [ ^ ]

谢谢,
Viprat
Hi,

see the below link it might be help you to solve your problem. The error occurs due to fetch so much data at a time. Better to fetch records in some interval. you can use paging. Might be it will solve your problem.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/60432190-8b83-4f9e-a21f-4c830a5005fc[^]
http://msdn.microsoft.com/en-us/library/tx1c9c2f%28v=vs.80%29.aspx[^]
http://www.dotnetspider.com/forum/234222-System.OutOfMemoryException-thrown-case-huge-data.aspx[^]

Thanks,
Viprat


Basically such scenario generate due to high execution sql query cost.
You can set appropriate timeout in connection string as below :

<appSettings>
        <add key="Connstr" value="Server=192.168.1.6\SQLExpress;database=Mydatabase;timeout=100000;uid=usename;pwd=password;"/>
    </appSettings>

and use below  preventive/precautionary steps for minize table scan :
1)Define appropriate index on database table.
2)Check query execution cose using explain plan.
3)Try to avoid such full table scan query.

Thanks & Regadrs
Prashant K.


这篇关于如果行数约为5811753,则将数据从数据库访问到数据集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆