Click to See Complete Forum and Search --> : Get computer name of current ODBC connection


James Kline
November 23rd, 1999, 09:01 AM
Does anyone know how to determine the computer name of the current ODBC connection.

For instance, I am connecting over a WAN to an ODBC Data Source via ADO. I want to know the computer name of the machine that I am connecting to. The user can change to DSN to connect to different machines, and I want to be able to determine the computer name of each machine.

If I was able to determine SQL Servers in a network on a 95/98 machine that would work too.

Thanks


James Kline
Simonton Windows, Inc.

Lothar Haensler
November 23rd, 1999, 09:21 AM
there is a NetServerEnum API that you can use to find all SQLServers (use SV_TYPE_SQLSERVER
flag) in your LAN.
I haven't tested this in W95/W98.

also, you can find the Servername from TSQL:
select @@servername

James Kline
November 23rd, 1999, 09:27 AM
The NetServerEnum API does not work with 95/98 machines from the information that I have gathered, but the select @@servername should work fine.

Thanks

James Kline
Simonton Windows, Inc.

Lothar Haensler
November 23rd, 1999, 09:34 AM
you might also want to try the following approach.
after calling the open method of the connection object the connectionstring property of the connection object contains the connectionstring after resolving all details.
It contains an Address= field, that contains the server name in my tests.

Dim cn as new ADODB.Connection
cn.Open "dsn=t0010;uid=xx;pwd=xx;database=xxx"



after calling cn.open, cn.Connectionstring contained "...Address=servername..."