none
How to detect bad connection strings (failed connections in general) RRS feed

  • Question

  • How can I tell if the connection information I supply when creating a DataContext is good? It seems that the failure occurs when I try to use the connection, i.e., execute a LINQ query. That seems totally lame! I do not want to have to put all my queries inside try blocks. I'd much rather test the connection somehow before I use it. There has to be some way to do this, no?
    Wednesday, March 24, 2010 10:58 PM

Answers

  • There is no way to know in advance that the connection is good. For example, the network can fail right before your query. Thus, you are stuck with try/catch blocks. 

    However, using little imagination and delegates they could be nicely wrapped into a helper class.


    Miha Markic [MVP C#] http://blog.rthand.com
    • Marked as answer by DrDad Thursday, March 25, 2010 2:00 PM
    Thursday, March 25, 2010 7:45 AM