954,198 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Loading All Database Name

i want to create a dropdownlist and when i click the dropdownlist, then it should show the all databases which is present in SQLserver. (now i m using SQLSERVER 2005 and Microsoft VISUAL STUDIO 2005) can anyone help me plz? thanks in advance. CLEAR MY DOUBT IF U GENIUS

karan_21584
Light Poster
32 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Just run a select query in the master database where the object is a database. anything in SQL Server has to be registered in the master database. When you create a table, stored proc, user etc. it is stored in the master database. Of course you need the correct permission to access the master database, but it is all there.

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

thanks sir.but i want to know what are all the databases avaliable in the SQLSERVER. for example... while we connecting the sqlserver through vb.net (OLEDB) we specify the username and password and just select the database know.the same thing i need in my application

karan_21584
Light Poster
32 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

just go through www.connectionstrings.com for all your db queries

amithasija
Light Poster
44 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 
just go through www.connectionstrings.com for all your db queries

- i gave all connection strings correctly. thats no problem sir.but i want to select "what are all the databases avaliable in SQLServer" (example....MASTER,TRAINEE,STUDENTS,....)..can u help me? thanks in advance

karan_21584
Light Poster
32 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
Just run a select query in the master database where the object is a database. anything in SQL Server has to be registered in the master database. When you create a table, stored proc, user etc. it is stored in the master database. Of course you need the correct permission to access the master database, but it is all there.

-
thanks sir.but i want to know what are all the databases avaliable in the SQLSERVER. for example... while we connecting the sqlserver through vb.net (OLEDB) we specify the username and password and just select the database know.the same thing i need in my application...can u help me? thanks in advance....

karan_21584
Light Poster
32 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Ok i will try again.
In SQL Server there is a system database called Master. This is the heart of SQL Server. Whenever you add an object to SQL Server such as a database, a user, a stored proc, a table, a column etc. it is put into the master database. Go look at the master database tables and you will see all your databases in there.
So alll you have to do is write a query to select all from the table in the master database where the object type is a database. e.g. select * from dbo.master.the_table_with_the_databasenames where the_type = the_database_type.
That is as close as i will go but it is just that one line. I could give you the select query but you will learn a lot more about SQL Server if you figure it out yourself.

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

Or you can just "EXEC sp_databases" look it up in Books on line (the manual that comes with SQL Server) find it from Start -> All programs -> Microsoft SQl Server -> Books online.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

Declare

'Add reference "Microsoft SQLDMO Object Library"
   Dim sqlServers As SQLDMO.NameList
    Dim sqlServerName As String


On event

sqlServers = New SQLDMO.Application().ListAvailableSQLServers

        For Each sqlServerName In sqlServers
            cboServerName.Items.Add(sqlServerName)
        Next
s_muenchaisit
Newbie Poster
2 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

Sorry

in fact you can use
"select name from master..sysdatabases where name<>'master' and name<>'tempdb' and name<>'model' and name<>'msdb'"

s_muenchaisit
Newbie Poster
2 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You