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?
I’m using SQLDriverConnect function to connect to database. In connection string I can specify
Share
Run the following query on your connection:This will return the server and instance name
The preferred form is apparently to use
SERVERPROPERY:which will return the server and instance name, and, unlike
@@SERVERNAME, correctly returns results if the server has been renamed.