Server=mySQLServer;Database=northwind;User ID=sa;Password=mypwd;" 

解决方案 »

  1.   

    每次访问后都要Close(),将连接放回连接池中。
      

  2.   

    用连接之前需要判断一下连接的状态,不过不是open那就先要open一下
    通常用好之后需要关闭,当然也可以选择不关闭,全局共享一个连接
    看应用具体而定
      

  3.   

    一般你可以这样写
    设sqlCon 为你的连接。
                try
                {
                    if (sqlCon.State != ConnectionState.Open)
                    {
                        sqlCon.Open();
                    }
                }
                catch
                {
                }
                finally
                {
                    if (sqlCon.State != ConnectionState.Closed)
                    {
                        sqlCon.Close();
                    }
                }
    这样就能及时关闭和打开需要的连接了
      

  4.   

    you'd better "try" before you go to connect,if happen some exceptions ,you may do nothing and you should close the connection at last!