0

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

Thanks in advance

1
  • Try adoConnectioObject.DataSource Return a string with a Commented May 17, 2019 at 22:14

3 Answers 3

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try to run:

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.