I am wondering if there is an elegant way to check for the existence of a DB? In brief, how do test the connection of a db connection string?
Thanks
Another way to see if your database is in use is to look and see if the indexes are being used. Information on index usage is held in the sys. dm_db_index_usage_stats table since the last server reboot, and can be queried using this statement which can be tailored to select the data you need.
Set the Initial Catalog=master
in the connection string and execute:
select count(*) from sysdatabases where name = @name
with @name
set to the name of the database.
If you want to check the connection string as a whole (and not existence of an independent database), try connecting to it in a try/catch
block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With