Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,
Is there any solution to get all database names available in PC in comboBox by selecting server name?
Posted
Updated 16-Mar-13 5:28am
v2
Comments
[no name] 14-Mar-13 10:21am    
Yes, yes there is.
Dev Gupta from Mumbai,India 14-Mar-13 10:26am    
Will you please give me the solution?
[no name] 14-Mar-13 10:34am    
Select the table names from your database and then populate your combobox with the result.

1 solution

You can connect any sqlserver database from your application and execute that query with ado.net.
SQL
SELECT name as DatabaseName FROM sys.Databases

You will got all database name from that sqlserver.
 
Share this answer
 
Comments
Dev Gupta from Mumbai,India 14-Mar-13 10:38am    
thanks for your reply.I tried this and I'm getting database names that are available in MicrosoftSqlServer folder in C:. But what if databases are in D: or in other drives?In short, I want database names that are available in Other drives also..
S. M. Ahasan Habib 14-Mar-13 12:57pm    
no matter where database stored where c: or d: or other drive. Application just connect to its database and execute its query. Database files(MDF,LDF) is hidden from application. So no problem will raise for that.
Dev Gupta from Mumbai,India 17-Mar-13 11:14am    
hii,
I had tried your given code.In comboBox I'm getting master database name,whereas my database name is testdb which is present in E:\newfolder\mydb.
S. M. Ahasan Habib 17-Mar-13 11:28am    
you execute SELECT * FROM sys.Databases query from your sql server management studio and see the results. If there you do not find your database name then let me know.
Dev Gupta from Mumbai,India 19-Mar-13 1:58am    
I'm getting master,temp db names.I want a code that should run in every pc after creating a setup.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900