Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test SqlServer connection without opening a database

The title pretty much says it all. I want to create a SqlConnection and then check that connection without opening a database, cause at that point I don't know yet where will I connect to. Is it possible to do that? The SqlConnection class has a 'Open' member which tries to open the database you'd set in the Database property, and if you didn't set one, SqlServer tries with the master db. The thing is the user I'm trying to connect with (MACHINE\ASPNET) has access to some databases (which I don't know yet) and not the master db.

Regards, Seba

like image 960
sebagomez Avatar asked Sep 30 '08 19:09

sebagomez


1 Answers

Connect to temp db. Everybody has accecss to tempdb so you will be able to authenticate yourself for access. Later when you know the actual database , you can change this property to connect to the db you want.

like image 113
Learning Avatar answered Oct 05 '22 12:10

Learning