当你使用sql server时,推荐使用SqlClient命名空间下的类,如SqlConnection、SqlDataReader等等,因为微软做了好多优化,性能是最好的。在实际运用时,个人建议你写一个数据访问类(DAL)。推荐你看看这几篇文章-- Improving .NET Performance : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenet.aspImproving ADO.NET Performance : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt12.aspStrategy for Building a Pluggable Data Access Layer in .NET: http://www.15seconds.com/issue/020611.htm
为什么要这么做?用的时候连接就可以了啊
Improving .NET Performance :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenet.aspImproving ADO.NET Performance :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt12.aspStrategy for Building a Pluggable Data Access Layer in .NET:
http://www.15seconds.com/issue/020611.htm
数据库联接你应该是在操作数据库的时候再打开,用完后立即释放
还是我在Session_start连数据库,在session_end释放连接?
谢谢
在application_end关闭,用的时候连不用了关就是了,随便写在哪里,我一般写在数据访问层里。
若嫌慢,可以配置连接池