我正在用 C# 编写 Web 应用程序,数据库是 MSSQL Express 2012。
当我使用 SqlDataAdapter
时出现错误:
ExecuteReader requires an open and available Connection.
连接的当前状态是连接。
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(dt);
我不知道如何修复它。谢谢
最佳答案
试试这个:
lock(conn)
{
DataTable dt = new DataTable();
using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand))
{
sqlDataAdapter.Fill(dt);
}
}
关于c# - 连接的当前状态是 connecting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27076625/