dcsimg
Results 1 to 3 of 3

Thread: Dsn odbc dao vb6

  1. #1

    Thread Starter
    Lively Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    94

    Dsn odbc dao vb6

    I need some advice on opening a MySql database DSN in VB6 with ODBC and DAO.
    The code I use fails, and I do not know why.

    Dim wsODBC As Workspace
    Set wsODBC = DBEngine.CreateWorkspace("ODBCWorkspace", "admin", "", dbUseODBC)
    Workspaces.Append wsODBC
    Dim Conn As Connection
    Set Conn = wsODBC.OpenConnection("Conn1", , , "ODBC;DSN=ibsmsbloem;") - this line gives an error OBDC call failed.
    Dim rs As Recordset
    Set rs = Conn.OpenRecordset("accountterms", dbOpenSnapshot)

    Is there some checklist through which I may work to check that I have done everything right or some examples.

    Thanks

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,431

    Re: Dsn odbc dao vb6

    Try
    Code:
    Dim Conn As Connection
    Set Conn = wsODBC.OpenConnection("IBSMSbloem")
    see: https://msdn.microsoft.com/de-de/lib.../ff196074.aspx
    If you specify a registered ODBC data source name (DSN) in the connect argument, then the name argument can be any valid string, and will also provide the Name property for the Connection object. If a valid DSN is not included in the connect argument, then name must refer to a valid ODBC DSN, which will also be the Name property.
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    I say you're crazy not to!
    --------------------------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  3. #3
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,223

    Re: Dsn odbc dao vb6

    Hi Peekay,

    it's been a while since I used DAO, but I'll have go....

    Code:
    Private Sub Command1_Click()
    Dim ws As Workspace
    Dim cn As Connection
    Dim qd As QueryDef
    Dim rs As Recordset
    
    Set ws = CreateWorkspace("SQL_Server_ODBC", "", "", dbUseODBC)
    
    Set cn = ws.OpenConnection("SQL_Server_Conn", dbDriverComplete, False, "ODBC;DSN=TestDaten;UID=USERNAME;")
    
    Set qd = cn.CreateQueryDef("")
    
    qd.SQL = "SELECT * FROM YourTable"
    qd.ODBCTimeout = 0
    
    Set rs = qd.OpenRecordset(dbOpenForwardOnly)
    
    MsgBox "Name: " & rs!dsName
    
    rs.Close
    Set rs = Nothing
    
    Set qd = Nothing
    
    cn.Close
    Set cn = Nothing
    
    Set ws = Nothing
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width