Results 1 to 2 of 2

Thread: ODBC Question

  1. #1
    Guest
    I have a situation where I am accessing a database via an ODBC connection. I have been trying to find out if there is a way to pull out the actual name of the database from this connection, through VB, and not just the provider or connection name.

    I have heard that there is an API call that can do this. Is there any truth to that? I can't find any such call.

    Does anyone know of a way to accomplish this? Point me in the right direction.

    TIA
    Zempet


  2. #2
    You could use the ODBC API's, ie.

    code:--------------------------------------------------------------------------------Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hwndParent As Long, ByVal fRequest As Integer, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long
    Private Const ODBC_ADD_DSN = 1 ' Add a new data source.
    Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) existing data source.
    Private Const ODBC_REMOVE_DSN = 3 ' Remove existing data source.
    Private Const ODBC_ADD_SYS_DSN = 4 ' Add data source
    Private Const ODBC_CONFIG_SYS_DSN = 5 ' Configure (edit) data source
    Private Const ODBC_REMOVE_SYS_DSN = 6 ' Remove data source

    Private Sub Command1_Click()
    On Error Resume Next
    If SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, _
    "Microsoft Visual FoxPro Driver", _
    "DSN=" & "New DSN Name" & Chr(0) & _
    "DESCRIPTION=" & "New DSN Description" & Chr(0) & _
    "SOURCETYPE=DBC" & Chr(0) & _
    "SOURCEDB=" & "Path and Filename of DBC" & Chr(0) & _
    "BACKGROUNDFETCH=YES" & Chr(0) & _
    "NULL=YES" & Chr(0) & _
    "DELETED=YES" & Chr(0) & _
    "EXCLUSIVE=NO" & Chr(0) & Chr(0)) Then
    MsgBox "DSN Created"
    Else
    MsgBox "Create Failed"
    End If
    End Sub--------------------------------------------------------------------------------
    Obvously I used this to create aVFP DSN, but you can easily adapt it to whatever DSN type you require.
    Daryl Collins

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