Getting the server name from a DSN

Posted on 2003-03-21
Medium Priority
Last Modified: 2010-05-18
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
Question by:JotaEme
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 16

Expert Comment

ID: 8198710

Author Comment

ID: 8201162
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
LVL 16

Expert Comment

ID: 8206209
Sorry, I sent you the wrong link, it was the next link in the sequence.  Here's the sample I meant to send:

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:


Where DSNNAME is the name of the DSN you are looking for.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 8208814
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?

LVL 16

Accepted Solution

twalgrave earned 200 total points
ID: 8209658
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.

Expert Comment

ID: 9446916
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 
Post your closing recommendations!  No comment means you don't care.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Starting up a Project
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question