Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

How to check connection before instantiating context in LINQ to Entities,

$
0
0
Hi Folks

I've been using LINQ to Entites with the graphical Entity Designer taking care of creating all ORM stuff for my DB.

Thus to use it I have something like the following that runs when my program loads.

VB Code:
  1. Dim myContext As myDataEntities
  2. '...
  3. Try
  4.     myContext =  New myDataEntites
  5. Catch ex As Exception
  6.     MessageBox.Show("Could not talk to DB")
  7.     Me.Close()
  8.     Exit Sub
  9. End Try

The problem is that if the connection is failing for some reason (e.g. I have no connection to the server the DB is on) it takes quiite a long while for anything at all to happen.

Is there a better way I can confirm access to the DB before trying to create the context? (The DB is on a remote server that may be connected via proxy over ethernet)

I did take a look at the generated code in the myData.Designer.vb from my .edmx, but couldn't really work out where it is that the connection to the DB is actually attempted.

Thanks

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>