Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to retrieve sql server dabase names

Status
Not open for further replies.

balajee

Programmer
Joined
Jun 29, 2000
Messages
134
Location
NZ
Hi

I am making an application where the user cans select a sql server and database name from combo box. How do I retrieve the server name and database names on the local machine or on the network?

Thanks,
 
You could try using this code, replace UserID, Password and Server with your server name, uid, and password.

This will retrieve database names from a SQL Server.
Good luck.


Private con As ADODB.Connection
Private rs As ADODB.Recordset

Private Sub Form_Load()

Set con = New ADODB.Connection

con.ConnectionString = "Provider='SQLOLEDB.1' ;User id ='USER ID' ;password='PASSWORD' ;Persist Security info='True' ; Data Source='SERVER' ;Connect Timeout=0; Initial Catalog='master'"

con.Open
Set rs = con.OpenSchema(adSchemaCatalogs)
Do Until rs.EOF
combo1.AddItem rs!CATALOG_NAME
rs.MoveNext
Loop

end sub
 
Thanks. This code worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top