SqlConnection Async Open

J

just4fun6969

I am creating an application that is designed to monitor a mission
critical in-house app. What I want to do is query the database to get
some basic stats and then display those stats to the user.

I am running into a problem when I try and open the database when the
database is down (The situation is the database is down and the
monitoring program processes alerts and prompts the user for action).

I can create async commands - but that IS NOT the solution to this
problem. It appears that the program will wait at the conn.open() call
until the timeout is reached at which time it throws an exception - I
believe this is true even when the conn.open is in it's own thread.

Is there anyway I can make the conn.open() call asynchronously?
Barring that solution, does anyone have a recommendation for a minimum
timeout?
 
M

Miha Markic

I can create async commands - but that IS NOT the solution to this
problem. It appears that the program will wait at the conn.open() call
until the timeout is reached at which time it throws an exception - I
believe this is true even when the conn.open is in it's own thread.

If you call Open() in a thread only that thread is blocked and not the
entire application. Thus, worker threads are a way to go in your case.
Is there anyway I can make the conn.open() call asynchronously?

As I said, do it in another thread, so only that thread is blocked.
 
W

William \(Bill\) Vaughn

Yes, running the Connection Open on a thread is a good idea, but it's far
easier to tell if the server is down. Of course, you also need to see if the
network is up first, but then you can ask the .NET factory classes to show
you the server instance state. This does not require an Open but it takes
far less time to execute. I show how to do this in some of my conference
sessions, in my workshop at Dev Connections and DevTeach (see
http://www.betav.com/TourSchedule/TourEvents.htm) as well as in my book.

hth

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top