I know how to execute commands on SQL server asynchronously using Begin/EndExecuteNonQuery, but is there a Begin/EndOpen method on the SqlConnection class? I would like this to be asynchronous because sometimes it is slow and I don't want to block a thread the whole time. Does this make sense?
There isn't a BeginConnect method, but you can fire up a new Thread and just do it in the background if that would work for you.
Or, to keep the same pattern, create a delegate with the method signature you want to have as async method and do a BeginInvoke
/EndInvoke
on the delegate.
Of course, this does not make the method really async as there is still a thread behind the scenes which waits for the sync method to return, but allows you to use the normal pattern and it uses a thread from the threadpool to make the call.
I would thread out the entire command execution, not just opening the connection. Just be careful how you handle working with the results once the thread is done.
You can, but it would be unusual for it to be very helpful. The scarce resource for databases usually isn't associated with connections, but with queries. Do you suspect that your application is blocking on opening connections?