Results 1 to 5 of 5

Thread: Creating a DSN for Text Database through Code

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    13
    Can any body out there Show me the Code for Programmatically creating a DSN for Connecting to a text Database .


    Thanks
    Suman Perumbully
    www.perumbully.itgo.com

  2. #2
    Lively Member
    Join Date
    Aug 1999
    Location
    Blackpool, England
    Posts
    87
    You can create a DSN using RDO's rdoRegisterDataSource method.
    If you need the code I can produce some for you.


  3. #3
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613
    Hi,

    I know how to create a User DSN using rdoRegisterDataSource method. Do you know how to create the System DSN using code?

    Regards,
    TheBao

  4. #4
    Lively Member ayyasaran's Avatar
    Join Date
    Feb 2001
    Location
    India
    Posts
    120
    Hi,

    The following API can be used to create a user, system DSN.

    Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long

    Regards,
    Saran.

  5. #5
    Lively Member
    Join Date
    Mar 1999
    Posts
    93
    Here's fully functional routines for creating/deleting DSN


    'Declarations Used to Generate DSN
    Private Const ODBC_ADD_DSN = 1 ' Add data source
    Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
    Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
    Private Const vbAPINull As Long = 0& ' NULL Pointer

    Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long

    Public Sub CreateDSN(sDSN As String)
    Dim nRet As Long
    Dim sDriver As String
    Dim sAttributes As String

    sDriver = "Oracle73 Ver 2.5"
    sAttributes = "Server=pressdb.world" & Chr$(0)
    sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)
    sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
    sAttributes = sAttributes & "DATABASE=DB" & Chr$(0)
    sAttributes = sAttributes & "UID=Vital" & Chr$(0)
    sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)

    DBEngine.RegisterDatabase "kiki", "Oracle73 Ver 2.5", True, sAttributes

    nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver, sAttributes)

    End Sub

    Public Sub DeleteDSN(sDSN As String)
    Dim nRet As Long
    Dim sDriver As String
    Dim sAttributes As String

    sDriver = "Oracle73 Ver 2.5"
    sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)

    nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver, sAttributes)

    End Sub

    Have fun!
    Regards,
    Vit

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