|
-
Mar 29th, 2000, 06:36 PM
#1
Thread Starter
Fanatic Member
I have to amend one of my projects so that it uses ADO instead of DAO. I need to connect via a DSN, but I want to create it in code. I usually do it with DBEngine.RegisterDatabase, but is there another way I can do it so that I do not have to add DAO references into my project?
Also how do I check if a DSN exists (apart from trying to connect to the DB and testing if it has suceeded)?
All help greatly appreciated!!
-
Mar 29th, 2000, 08:41 PM
#2
Lively Member
I usually work with data link files (right click in explorer, new, Microsoft data link).
The connect string for a data link file is
File Name=datalinkfile
Roger
-
Mar 29th, 2000, 09:08 PM
#3
Thread Starter
Fanatic Member
I've managed to create a dsn by using the SqlConfigDataSource API (I found it in an earlier post), but can anyone tell me how to check if a dsn already exists?
-
Mar 29th, 2000, 10:16 PM
#4
You can use this function I wrote. Put this in a module:
Code:
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CURRENT_USER = &H80000001
Private Const ERROR_SUCCESS = 0&
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_NOTIFY = &H10
Private Const READ_CONTROL = &H20000
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const SYNCHRONIZE = &H100000
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Enum enumDSNType
eUser = 1
eSystem = 2
End Enum
Public Function IsDSNExist(pDSNName As String, pType As enumDSNType) As Boolean
Dim lKeyHandle As Long
Dim lRet As Long
Dim strBuffer As String
Dim strKey As String
Dim strValue As String
strKey = "SOFTWARE\ODBC\ODBC.INI\" & pDSNName
If pType = eSystem Then
lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_READ, lKeyHandle)
Else
lRet = RegOpenKeyEx(HKEY_CURRENT_USER, strKey, 0, KEY_READ, lKeyHandle)
End If
If lRet = ERROR_SUCCESS Then
IsDSNExist = True
RegCloseKey lKeyHandle
End If
End Function
Then you can use it like this:
MsgBox IsDSNExist("MyDSNName", eSystem)
-
Mar 29th, 2000, 11:37 PM
#5
Thread Starter
Fanatic Member
Cheers Serge, thats just what I needed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|