I am writing web application in C#, and database is MSSQL Express 2012.
When i use SqlDataAdapter
i get the Error:
ExecuteReader requires an open and available Connection.
The connection's current state is connecting.
SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn);
da.Fill(dt);
I can not figure how to fix it. Thankss
Try this :
lock(conn)
{
DataTable dt = new DataTable();
using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand))
{
sqlDataAdapter.Fill(dt);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.