If the Connection fails to open, there is nothing more you can do: you cannot proceed to use the connection - that's like turning up the radio in your car to cover the sound of metal on tarmac because all four tires have burst ... It's not going to "magically go away" and work the next time you try.
try...catch
isn't there to ignore problems - it's there so you can gracefully fail and report them without your application crashing out on your user.
Quote:
I'm not trying to ignore the problem per say, I'm trying to get the program to generate the table of averages regardless of the failed connection.
So if I had 3 connections; the first and third connection in the list work however the second doesn't. I don't want the foreach loop to end on the second connection, I want it to grab the information it can from the two working connections to form the table.
Then the try block has to surround ALL the code that uses it, not just the attempt to open the connection:
foreach (string item in itemList)
{
try
{
connectionString = string.Format(theString, item); /
using (SqlConnection sqlConnect = new SqlConnection(connectionString))
{
sqlConnect.Open();
sqlQuery1 = new SqlDataAdapter("my sql query",sqlConnect);
createTable();
...
}
}
catch {}
}