Results 1 to 3 of 3

Thread: kinda urgent......

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    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.

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    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."

  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    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
  •  



Click Here to Expand Forum to Full Width