What's the easiest way to check if a database exists in MSSQL using VB.NET?
3 answers
Connect to the system db (master, msdb, tempdb or model) - because you can be sure they exist! Then you can select the database list like this:
select * from sys.databases
or if you want to know if a specific db exists:
select * from sys.databases where name = 'NameOfYourDb'
If you connect without a database name in your connection string (belongs to whichever provider you are using) you should automatically connect to the default database (which is "wizard" by default)
+4
source to share