The connection's current state is connecting

1.3k views Asked by At

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

1

There are 1 answers

1
Rahul Sharma On BEST ANSWER

Try this :

lock(conn)
{
    DataTable dt = new DataTable();
    using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand))
    {
        sqlDataAdapter.Fill(dt);
    }
}