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?
-
Did you look at the OutConnectionString SQLDriverConnect returns? It might contain what you need.bohica– bohica2012-10-29 10:12:24 +00:00Commented Oct 29, 2012 at 10:12
-
SQLGetInfo + SQL_SERVER_NAME ?Alex K.– Alex K.2012-10-29 11:30:46 +00:00Commented Oct 29, 2012 at 11:30
Add a comment
|
1 Answer
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.
1 Comment
BSen
I will consider this, but aren't there any way to do this without making any queries?