Tuesday, March 24, 2009

Error while opening connection with sql as connection is already open using asp.net and c#?

There may e scenario where you are getting error while establishing connection with the database as connection is already open.

it can be easily solved using
if (mysqlcmd.Connection.State == ConnectionState.Closed)
{
mysqlcmd.Connection.Open();
}

//same for closing the connection
if (mysqlcmd.Connection.State == ConnectionState.Open)
{
mysqlcmd.Connection.Close();
}

No comments:

Post a Comment