checking for a specific ODBC connection

I need a way to check for an existing ODBC connection in the odbc data source administrator.  All the research I have done indicates that the values are stored in either the INI file (not in XP) or the registry.  I have determined that the ini file does not exist and I do not have access to the registry on this computer so my search skills are limited here.  What I would like an easy way to see if the the connection named "tempconn" exists in the registry so that my code does not update the connection information when I use RegisterDatabase to establish the missing connection.  This is all being done on an xp system (soon to be vista) inside a ms access database.
LVL 8
Joe OvermanEngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rockiroadsCommented:
What code are you currently using, r u using the sqlconfig... api? if so then could you not try to open as edit. If it failed then try to add on. If that fails then summat is knackered or it already exists!
0
vincem1099Commented:
Seems like you would be able to read the registry if you can add the connection to the registry with the registerdatabase command.  The function will return true if connection name exists.
Function ConnectionExists(sConnectionName As String) As Boolean
Const HKEY_CURRENT_USER = &H80000001
Dim objReg As Object
Dim strComputer, strkeypath As String
Dim arrValueNames As Variant
Dim subkey As Variant
 
strComputer = "."
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strkeypath = "Software\ODBC\ODBC.ini"
 
objReg.enumkey HKEY_CURRENT_USER, strkeypath, arrValueNames
 
For Each subkey In arrValueNames
    If sConnectionName = subkey Then
        ConnectionExists = True
    End If
    
Next
 
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
> the ini file does not exist and I do not have access to the registry on this computer ..

Then you are left with trial and error.
Open a connection assuming your DSN exists. Catch an error.
If no error is catched, the DSN exists.

/gustav
0
Joe OvermanEngineerAuthor Commented:
That is just what I need.  Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.