How can i browse database name and server to connect?
MsSQL Database browser
Collapse
X
-
To query the database for other objects you need to connect to it first. Usually one knows the server name and the database name. So you don't know both? So what information do you currently have about the database? If you have nothing then ask the person that installed the database. -
i know server name(actually it is localhost), but database create user and name can be various.
so i have connection line:
I need to browse Initial Catalog of my DBCode:SqlConnection connection = new SqlConnection("Data Source=(local)\\DB_name;Initial Catalog="can_be_various";Integrated Security=True");Comment
-
Outside .NET you would run thesql.Code:EXEC sp_databases
In .NET you can use the SQL Server Managed objects see guide here http://msdn.microsoft.com/en-us/library/ms162169.aspx
Then you can get the server using
and the databases usingCode:server = new Microsoft.SqlServer.Management.Smo.Server("localhost");Code:server.Databases
Comment
Comment