I'm using SQLDriverConnect function to connect to database. In connection string I can specify ODBC pre-configured data source name (DSN), function resolves necessary attributes and all works fine. But after successful connection I need to get instance name to which I have connected or connection port (because there can be several instances of mssql running on server). How can I implement this?
问问题
1258 次
1 回答
1
Run the following query on your connection:
select @@SERVERNAME
This will return the server and instance name
The preferred form is apparently to use SERVERPROPERY
:
SELECT SERVERPROPERTY('ServerName')
which will return the server and instance name, and, unlike @@SERVERNAME
, correctly returns results if the server has been renamed.
于 2012-10-29T08:03:02.090 回答