|
-
Jun 13th, 2000, 12:00 PM
#1
Thread Starter
Hyperactive Member
Hi,
I need to create a DSN from my vb app. This I've managed. What I haven't figured out is how to check if a DSN of that name already exists. How can this be done. Any help will be appreciated.
Thanks,
Rammy.
-
Jun 13th, 2000, 03:36 PM
#2
Frenzied Member
Although it's not what you asked, the best answer is not to use a DSN since then you don't have to rely on it being setup properly on the PC. If you specify the driver, server and database you can avoid using DSNs at all.. eg;
MyConnection.Open "Provider=SQLOLEDB;Driver={SQL Server};Server=MYSERVER;Database=MYDB;UID=SA;PWD=;"
will open the connection without being told a DSN.
The other thing is once you've got a DSN set up on a PC the user could then use your DSN to access the data without your program - which could be a security risk.
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Jun 13th, 2000, 06:56 PM
#3
Fanatic Member
Try the following :
Code:
Public Function DSNExist(strDSNName As String) As Boolean
'***************************************************************************
'Purpose: Determines whether a DSN already exists.
'Parameters: strDSNName - DSN Name to be checked for.
'Returns: True/False - DSN Exists.
'***************************************************************************
On Error GoTo ErrorHandler
Dim lngKeyHandle As Long
Dim lngReturn As Long
Dim strKey As String
DSNExist = False
strKey = "SOFTWARE\ODBC\ODBC.INI\" & strDSNName
' Open registry key
lngReturn = RegOpenKeyEx(HKEY_CURRENT_USER, strKey, 0, KEY_READ, lngKeyHandle)
If lngReturn = ERROR_SUCCESS Then
DSNExist = True
' Close registry key
RegCloseKey lngKeyHandle
End If
End Function
Hope this helps
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
|