Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

Getting the server name from a DSN

Hi all,

How can I get the server name given a SQLServer DSN?
How can I get the database path of an Access DSN?

I suppose that odbc32.dll could help me, but I don't know
the right function to call from my Visual Basic .Net program.

Thanks in advance
0
JotaEme
Asked:
JotaEme
  • 3
  • 2
1 Solution
 
JotaEmeAuthor Commented:
Hi again,

Thank you very much for the information, nevertheless, I'm
afraid it's not what I need :-(

This code shows the System and User DSNs, and what I want
is to retrieve the SQLServer name given a DSN name.
I already use a piece of code similar to the one
provided by you in order to fill up a combo box, but what
I need is to know which is the server name of the DSN
selected by the user.

If possible, I would also like to know the path of the Access file (in case the DSN represented an Access one).

Best regards
0
 
twalgraveCommented:
Sorry, I sent you the wrong link, it was the next link in the sequence.  Here's the sample I meant to send:
http://www.mvps.org/vbnet/index.html?code/system/sqldatasources.htm

This is only a sample and still the native code doesn't show you how to retrieve what you want, but does show you the methods to retrieve the ODBC data sources and obtain some info fromt he registry.  With that in mind, you can get to the following Registry areas to get your DB location info:

HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\DSNNAME\DBQ

Where DSNNAME is the name of the DSN you are looking for.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
JotaEmeAuthor Commented:
Thanks again,

What you mean is that I have to work with the registry, don't you?.

I have already had a look at the registry, but my concern is: is the registry structure the same regarless your O.S. and the versions of the drivers?

If not, my applications won't work propery in a different O.S. or using a different version of the ODBC drivers, am I wrong?

Bye
0
 
twalgraveCommented:
The registry settings for the DSNs has remained intact across all versions that I have worked with.  Unfortunately, I don't have XP, but it should be a simple matter of finding an XP box and checking to see if the registry locations are the same.  Also, it's been a while for me with 95/98, but these might have stored the DSN info into the ODBC.INI file.  The GetPrivateProfileString API can be used in this circumstance.
0
 
CleanupPingCommented:
JotaEme:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now