日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
教你使用DataAdapter優(yōu)化ADO.NET連接池

經(jīng)過長時間學習ADO.NET連接池,于是和大家分享一下,看完本文你肯定有不少收獲,希望本文能教會你更多東西。用于ODBC的SQL Server、OLE DB和.NET框架數(shù)據(jù)提供程序隱式緩沖連接。通過在連接字符串中指定不同的屬性值,可以控制ADO.NET連接池的行為。

成都創(chuàng)新互聯(lián)從2013年成立,先為金堂縣等服務(wù)建站,金堂縣等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為金堂縣企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

#T#DataAdapter 的Fill和Update方法在連接關(guān)閉的情況下自動打開為相關(guān)命令屬性指定的連接。如果Fill或Update方法打開了連接,F(xiàn)ill或Update 將在操作完成的時候關(guān)閉它。為了獲得***性能,僅在需要時將與數(shù)據(jù)庫的連接保持為打開。同時,減少打開和關(guān)閉多操作連接的次數(shù)。如果只執(zhí)行單個的Fill或Update方法調(diào)用,建議允許Fill或Update方法隱式打開和關(guān)閉連接。如果對Fill和Update調(diào)用有很多,建議顯式打開連接,調(diào)用Fill和Update,然后顯式關(guān)閉連接。另外,當執(zhí)行事務(wù)時,顯式地在開始事務(wù)之前打開連接,并在提交之后關(guān)閉連接。例如:

 
 
  1. 'Visual Basic
  2. Public Sub RunSqlTransaction(da As SqlDataAdapter, myConnection As SqlConnection, ds As DataSet)
  3. myConnection.Open()
  4. Dim myTrans As SqlTransaction = myConnection.BeginTransaction()
  5. myCommand.Transaction = myTrans
  6. Try
  7. da.Update(ds)
  8. myTrans.Commit()
  9. Console.WriteLine("Update successful.")
  10. Catch e As Exception
  11. Try
  12. myTrans.Rollback()
  13. Catch ex As SqlException
  14. If Not myTrans.Connection Is Nothing Then
  15. Console.WriteLine("An exception of type " & ex.GetType().ToString() & " was encountered while attempting to roll back the transaction.")
  16. End If
  17. End Try
  18. Console.WriteLine("An exception of type " & e.GetType().ToString() & " was encountered.")
  19. Console.WriteLine("Update failed.")
  20. End Try
  21. myConnection.Close()
  22. End Sub
  23. //C#
  24. public void RunSqlTransaction(SqlDataAdapter da, SqlConnection myConnection, DataSet ds)
  25. {
  26. myConnection.Open();
  27. SqlTransaction myTrans = myConnection.BeginTransaction();
  28. myCommand.Transaction = myTrans;
  29. try
  30. {
  31. da.Update(ds);
  32. myCommand.Transaction.Commit();
  33. Console.WriteLine("Update successful.");
  34. }
  35. catch(Exception e)
  36. {
  37. try
  38. {
  39. myTrans.Rollback();
  40. }
  41. catch (SqlException ex)
  42. {
  43. if (myTrans.Connection != null)
  44. {
  45. Console.WriteLine("An exception of type " + ex.GetType() +" was encountered while attempting to roll back the transaction.");
  46. }
  47. }
  48. Console.WriteLine(e.ToString());
  49. Console.WriteLine("Update failed.");
  50. }
  51. myConnection.Close();

分享標題:教你使用DataAdapter優(yōu)化ADO.NET連接池
文章位置:http://www.dlmjj.cn/article/cdihhjh.html