Reputation: 2159
I have a query I am creating a Window App in vb.net (4.0) in which I have to use multiple databases although all databases are same with same db structure & stored procedures,just names are different. In the very starting of application, I need to give a option to the user that these are available db & user will select which one to connect & use.
So is it possible to detect how many db are available in the SQL Server through vb.net & how can achieve this (to provide options to the user) ? What would be the best approach?
Thanks
Upvotes: 0
Views: 1170
Reputation: 36126
sure, you just have to call any procedure on the server that can list the DB's for you. Try:
EXEC sp_databases
EXEC sp_helpdb
there is also an Un-Documented Procedure
EXEC sp_msForEachDB 'PRINT ''?'''
Upvotes: 0
Reputation: 62093
It dependso n permissions.
Basically you can always conect to the server and ask the server. All metadaa is available in the system management database and you can submit sql there to ask for waht databases exist.
Get list of databases from SQL Server
Upvotes: 1
Reputation: 13551
The sql server knows how many databases are installed, you can just query it. Your login needs to have permission to make the query, so you probably will want to use different connection strings for this query vs others.
Also, given the right permissions you can discover not only if the database exist, but whether it is structually acceptable
Upvotes: 1