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 开发者_如何学Pythonmy query.
Thanks in advance
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;
}
Try to run:
SELECT @@ServerName AS ServerName,
@@ServiceName AS ServiceName
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.
精彩评论