user239635
user239635

Reputation: 301

Get Sql Server instance name using Adodb conncection object

I need SQL server 2005 instance name from Adodb connection object in c#. Please Help for my query.

Thanks in advance

Upvotes: 0

Views: 2142

Answers (3)

marc_s
marc_s

Reputation: 754478

The ADODB connection itself doesn't have that information avaiable.

You can either run the SQL query:

SELECT SERVERPROPERTY('instancename') 

using your connection, or you can use the SMO (SQL Server Management Objects) to get that information:

using(SqlConnection _con = new SqlConnection(your-connection-string))
{
   string instanceName = new Microsoft.SqlServer.Management.Smo.Server
                            (new ServerConnection(_con)).InstanceName;
}

Upvotes: 1

DOK
DOK

Reputation: 32841

If you are stepping through C# code that is making a call to the database, and you don't know where it is getting the connection string from, you can set a breakpoint in the code right around the place where it makes the database call. Then, you can examine the properties of the various objects that are present. For example, check the Connection property of the SqlCommand. The database instance will be included in the connection string.

Upvotes: 0

Rubens Farias
Rubens Farias

Reputation: 57946

Try to run:

SELECT @@ServerName  AS ServerName,
       @@ServiceName AS ServiceName

Upvotes: 0

Related Questions