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: 418
  • Last Modified:

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.
0
Joe Overman
Asked:
Joe Overman
1 Solution
 
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

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