Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Querying the registry for database type of ODBC DSN

Querying the registry for database type of ODBC DSN

Querying the registry for database type of ODBC DSN

I am trying to determine the database type of a database from the ODBC DSN that is set up on the client computer.
I cannot seem to get enough reliable information from the connect string once the database is opened and am trying to query the value:
I can open the key using the "RegOpenKey" API but cannot either enumerate the key values or retrieve any of the key values. I have tried both "RegEnumValueEx" and "RegQueryValueEx" but both return an error. Am I right in thinking that if the API call asks for a data type "Byte" then I set up a Byte array and send the first element of the array to the API call? This is necessary with "RegQueryValueEx".
Thanks in advance to any API experts out there.
Replies continue below

Recommended for you

RE: Querying the registry for database type of ODBC DSN

In the absence of any replies I managed to sort the problem out myself. Here is the source for the problem. I was trying to query an ODBC DSN to determine whether the database type was Access or SQL Server:-
Public Function GetDatabaseType(vsConnect As String, vtType As DatabaseType) As Boolean

'This function will Query the registry for the string value of the DSN passed and will analyse the
'string to return one of the database types.

Dim lKeyHandle As Long
Dim sData As String
Dim lRetHandle As Long
Dim lReturn As Long
Dim lLenReturnValue As Long
Dim lType As Long
Dim sRetString As String
Dim sDSNName As String

'Get the DSN name from the connect string
sDSNName = Mid(vsConnect, InStr(vsConnect, "DSN=") + 4)
sDSNName = Left(sDSNName, InStr(sDSNName, ";") - 1)

lReturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.ini\ODBC Data Sources", 0, KEY_QUERY_VALUE, lRetHandle)
If lReturn <> 0 Then
Err.Raise erRegistryError, "clsArchive::GetDatabaseType", "Unable to open the ODBC Data Sources registry key."
Exit Function
End If

sData = String$(1024, 0)
lLenReturnValue = 1024
lReturn = RegQueryValueEx(lRetHandle, sDSNName, 0, lType, sData, lLenReturnValue)
If lReturn <> 0 Then
Err.Raise erRegistryError, "clsArchive::GetDatabaseType", "Unable to retrieve the registry key value (" & sDSNName & ")."
RegCloseKey lRetHandle
Exit Function
GetDatabaseType = True
sRetString = Left(sData, lLenReturnValue - 1)
If InStr(UCase(sRetString), "ACCESS") > 0 Then
vtType = dtAccess
ElseIf InStr(UCase(sRetString), "SQL SERVER") > 0 Then
vtType = dtSQLServer
vtType = dtUnknown
End If
GetDatabaseType = True
End If

RegCloseKey lRetHandle

End Function

Well, somebody may be wondering!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close