zoukankan      html  css  js  c++  java
  • 高效使用连接的模式

    使用连接的时候推荐使用下面的模式来处理连接:

    string source = "server=(local);" + " integrated security = SSPI;" + " database = Students";
    
                try
                {
                    using (SqlConnection conn = new SqlConnection(source))
                    {
                        // Open the connenction
                        conn.Open();
    
                        // Do something useful
    
                        // Close the connection
                        conn.Close();
                    }
                }
                catch(SqlException ex)
                {
                    // Log the exception
                }
    

    这样可以确保资源得到有效释放,不至于导致SQL可能出现的表会被锁住不能访问的情况。

  • 相关阅读:
    JZOJ5809 数羊
    P3313 [SDOI2014]旅行
    2019.10.22 NOIP模拟测试 day2
    P4322 [JSOI2016]最佳团体
    P1850 换教室
    P3225 [HNOI2012]矿场搭建
    P2607 [ZJOI2008]骑士
    2019.10.21 NOIP模拟测试 day1
    AFO
    禁止加载浏览器图片
  • 原文地址:https://www.cnblogs.com/herbert/p/1774234.html
Copyright © 2011-2022 走看看