daimous
Jun 22nd, 2007, 05:34 PM
hi guys! I just want to know if there is a better way, than the code below, for testing the connection to my ms sql 2000 server where in i can get the specific error message and "translate" it to words that my "dumb user" can understand. Thanks in advance!
public static bool TestDBConnection(string ConnStr)
{
bool returnVal = false;
SqlConnection sqlCon = new SqlConnection(ConnStr);
try
{
sqlCon.Open();
returnVal = true;
}
catch (SqlException ex)
{
MessageBox.Show("Connection Failed!\r\nMessage: " + ex.Message, "Test Connection",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
sqlCon.Close();
}
return returnVal;
}
public static bool TestDBConnection(string ConnStr)
{
bool returnVal = false;
SqlConnection sqlCon = new SqlConnection(ConnStr);
try
{
sqlCon.Open();
returnVal = true;
}
catch (SqlException ex)
{
MessageBox.Show("Connection Failed!\r\nMessage: " + ex.Message, "Test Connection",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
sqlCon.Close();
}
return returnVal;
}