Gustavo

Gustavo

  • NA
  • 1.3k
  • 453.9k

Try / Catch - Not catching error

Mar 5 2010 2:21 AM

Hello:
 
I thought that if there is an error between the 'try' it would execute the 'catch'? Below is my code and its seems its not catching the error on the TestConnection.Open();
 
try
{
SqlConnection TestConnection = new SqlConnection();
TestConnection.ConnectionString =
@"Server=hpw7v64.ggamvpn.gbridge.net;Database=IPDev;User ID=**********;Password=**********;";
TestConnection.Open();   //<<<ERROR - If the server is stopped.
//
SqlDataAdapter TestDataAdapter = new SqlDataAdapter("SELECT * FROM [User]", TestConnection);
DataSet TestDataSet = new DataSet();
//
TestDataAdapter.Fill(TestDataSet);
dataGridViewMSSQLHP.DataSource = TestDataSet.Tables[0];
dataGridViewMSSQLHP.Refresh();
}
catch (SqlException SQLExecute)
{
MessageBox.Show("Connection failed...MSSQL HP" + SQLExecute, "Test Connection...", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Answers (7)