Results 1 to 5 of 5

Thread: Adding DSN programmaticly - resolved

  1. #1

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747

    Adding DSN programmaticly - resolved

    SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, "MySQL ODBC 3.51 Driver", "DSN=MySQLTesting" & Chr(0)
    & "SERVER=myServer.com.au" & Chr(0) & "DATABASE=testing" & Chr(0) &
    "OPTION=" & (1 + 2 + 8 + 32 + 2048 + 16384) & Chr(0) & "UID=username" & Chr(0)
    & "PORT=3306" & Chr(0)
    & "DESCRIPTION=someDesc" & Chr(0))


    It returns 1 ie succesful, yet i cant see it my ODBC datasources list (through administritive options)

    help!?
    Last edited by SkiNLaB; Jun 16th, 2003 at 11:36 PM.

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    Try this

    VB Code:
    1. Option Explicit
    2.  
    3. 'Declarations Used to Generate DSN
    4. Private Const ODBC_ADD_DSN = 1 ' Add data source
    5. Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
    6. Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
    7. Private Const vbAPINull As Long = 0& ' NULL Pointer
    8.  
    9. Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal
    10. hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String,
    11. ByVal lpszAttributes As String) As Long
    12.  
    13. 'Code:
    14. Public Sub CreateDSN(sDSN As String)
    15.   ' * Comments : Create a DSN
    16.  
    17.    Dim nRet As Long
    18.    Dim sDriver As String
    19.    Dim sAttributes As String
    20.  
    21.    sDriver = "Oracle73 Ver 2.5"
    22.    sAttributes = "Server=pressdb.world" & Chr$(0)
    23.    sAttributes = sAttributes & "DESCRIPTION=" & sDSN & Chr$(0)
    24.    sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
    25.    sAttributes = sAttributes & "DATABASE=DB" & Chr$(0)
    26.    sAttributes = sAttributes & "UID=Waty" & Chr$(0)
    27.    sAttributes = sAttributes & "PWD=myPassword" & Chr$(0)
    28.  
    29.    DBEngine.RegisterDatabase "kiki", "Oracle73 Ver 2.5", True, sAttributes
    30.  
    31.    'nRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, sDriver,sAttributes)
    32.  
    33. End Sub
    34.  
    35. Public Sub DeleteDSN(sDSN As String)
    36.    ' * Comments : Delete a DSN
    37.  
    38.    Dim nRet As Long
    39.    Dim sDriver As String
    40.    Dim sAttributes As String
    41.  
    42.    sDriver = "Oracle73 Ver 2.5"
    43.    sAttributes = sAttributes & "DSN=" & sDSN & Chr$(0)
    44.  
    45.    nRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, sDriver,sAttributes)
    46.  
    47. End Sub
    oh1mie/Vic


  3. #3

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    whats dbengine? i am guessing its DAO, which i dont want to add to my project, I'd really like to get this API working.

    thanks.

  4. #4

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    Bump

  5. #5

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    ugh, i ams teh dumb, i didnt have my constants at the right values. *sigh*

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