I'm using LINQ to SQL (dbml) and i'd like to check if the connection to the connection string is valid before going further.. for example, if the IP in the connection string is incorrect (or the database goes down), the program crashes and would like to make a check for this. I tried this:
if (DataContext.DatabaseExists())
MessageBox.Show("Connection Exists");
That works if the connection is valid, but if the connection is invalid, it freezes at the if statement. What else can I try or do?
<add name="NflDataEntities" connectionString="metadata=res://*/NflData.csdl|res://*/NflData.ssdl|res://*/NflData.msl;provider=System.Data.SqlClient;provider connection string="data source=10.10.***.***;initial catalog=NflData;persist security info=True;user id=*****;password=****;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />