What is a better way than try/catch wrapping to verify that the connection on a TableAdapter opened or will open successfully?
public class MyItemParser
{
private myTableAdapter fa;
public FacultyParser()
{
this.fa = new facultyTableAdapter();
}
public bool HasValidConnection()
{
try
{
this.fa.Connection.Open();
}
catch(exception e)
{
return false;
}
return true;
}
public void FillList(IList<myItem> list)
{
foreach (var row in this.fa.GetData())
/**** DoSomething ****/
}
}
You should use the try and catch (I usually put the connection handling on a different class)
You might check (if you keep the connection open ) for the connection state but it doesn’t mean anything if the state is open (not reliable enough). In one project I even issued a dummy SQL request to test the connection before I handle it to the actuall class that uses it.