F
fish
Hi,
If I use the connection pool (It is default) in ADO sql server provider,
it will get trouble to run any sql after the sql server restarted.
Is ther a way to detect the pooling connection is valid ?
The SqlConnection state is useless.
It can not reflect the real situation when we use pooling connection.
If I switch to use non pooling connection, it is ok.
I still prefer to use pooling connection. Is any way to solve the problem ?
Thanks.
The sample code that I get the trouble is below.
try
{
string connectionstring ="Server=localhost;Initial Catalog=NorthWind;user id=sa;pwd=sapassword";
string strquery = "select * from categories";
string strcolumn = "categoryid";
//connectionstring += ";Pooling=false";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionstring;
conn.Open();
SqlCommand cmd = new SqlCommand(strquery,conn);
SqlDataReader reader = cmd.ExecuteReader();
int id ;
while( reader.Read() )
{
id= reader.GetInt32( reader.GetOrdinal(strcolumn));
//Debug.WriteLine(id.ToString());
}
reader.Close();
conn.Close();
// Net Stop mssqlserver
// Net Start mssqlserver
conn = new SqlConnection();
conn.ConnectionString = connectionstring;
conn.Open();
//Debug.WriteLine("ServerVersion: " + conn.ServerVersion
+ "\nState: " + conn.State.ToString());
cmd = new SqlCommand(strquery,conn);
reader = cmd.ExecuteReader(); // Exception will raise here
while( reader.Read() )
{
id= reader.GetInt32( reader.GetOrdinal(strcolumn));
//Debug.WriteLine(id.ToString());
}
reader.Close();
conn.Close();
}
catch( Exception ex)
{
string str = ex.Message; //"General network error. Check your network documentation.
//Debug.WriteLine(str);
}
Guo
If I use the connection pool (It is default) in ADO sql server provider,
it will get trouble to run any sql after the sql server restarted.
Is ther a way to detect the pooling connection is valid ?
The SqlConnection state is useless.
It can not reflect the real situation when we use pooling connection.
If I switch to use non pooling connection, it is ok.
I still prefer to use pooling connection. Is any way to solve the problem ?
Thanks.
The sample code that I get the trouble is below.
try
{
string connectionstring ="Server=localhost;Initial Catalog=NorthWind;user id=sa;pwd=sapassword";
string strquery = "select * from categories";
string strcolumn = "categoryid";
//connectionstring += ";Pooling=false";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionstring;
conn.Open();
SqlCommand cmd = new SqlCommand(strquery,conn);
SqlDataReader reader = cmd.ExecuteReader();
int id ;
while( reader.Read() )
{
id= reader.GetInt32( reader.GetOrdinal(strcolumn));
//Debug.WriteLine(id.ToString());
}
reader.Close();
conn.Close();
// Net Stop mssqlserver
// Net Start mssqlserver
conn = new SqlConnection();
conn.ConnectionString = connectionstring;
conn.Open();
//Debug.WriteLine("ServerVersion: " + conn.ServerVersion
+ "\nState: " + conn.State.ToString());
cmd = new SqlCommand(strquery,conn);
reader = cmd.ExecuteReader(); // Exception will raise here
while( reader.Read() )
{
id= reader.GetInt32( reader.GetOrdinal(strcolumn));
//Debug.WriteLine(id.ToString());
}
reader.Close();
conn.Close();
}
catch( Exception ex)
{
string str = ex.Message; //"General network error. Check your network documentation.
//Debug.WriteLine(str);
}
Guo