小编Pat*_*uis的帖子

连接不会像它应该关闭

我在ASP项目中遇到以下错误:

The connection was not closed. The connection's current state is open
Run Code Online (Sandbox Code Playgroud)

在SqlConnection对象上调用.open()函数时.

我试过这个:

    if (Conn.State != ConnectionState.Closed)
    {
        Log.Message(xxx);
        try
        {
            Conn.Close();
        }
        catch (Exception ex)
        {
            Log.Error(xxxx);
        }
    }
    Conn.Open();
Run Code Online (Sandbox Code Playgroud)

但这仍然会引发错误.Conn对象声明为:

private static readonly SqlConnection Conn = new SqlConnection(xxxx);
Run Code Online (Sandbox Code Playgroud)

知道我应该在哪里寻找解决方案

c# asp.net sqlconnection

2
推荐指数
1
解决办法
80
查看次数

标签 统计

asp.net ×1

c# ×1

sqlconnection ×1