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

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可能出现的表会被锁住不能访问的情况。

相关文章:

  • 2021-05-07
  • 2022-01-04
  • 2021-10-02
  • 2021-07-10
  • 2021-06-16
  • 2021-12-21
  • 2021-08-02
猜你喜欢
  • 2022-12-23
  • 2023-03-16
  • 2021-04-27
  • 2022-01-06
  • 2021-11-26
  • 2022-02-17
  • 2022-01-28
相关资源
相似解决方案