List:MySQL ODBC« Previous MessageNext Message »
From:Ed Carp Date:November 27 2002 8:43pm
Subject:RE: connection to DAO.connection fails usin myodbc
View as plain text  
> Unfortunately the the DAO samples I found in the myodbc-FAQ do not work.
> Neitehr from within Access nor from plain VB.
> The ADO samples work though.

This is from actual, working code - VB 6.0:

Dim MyDB As Database, MyRS As Recordset

' grab NameStr, ConnectStr from registry
NameStr = GetSetting(App.EXEName, "CONNECTION", "NSTR")
ConnectStr = GetSetting(App.EXEName, "CONNECTION", "CSTR")
If ConnectStr = "" Then ConnectStr = "ODBC;"
Debug.Print NameStr
Debug.Print ConnectStr
MyDBName = "LocalDB.MDB"

' what this code does is connect via ODBC - if that fails, connect to the
local database
On Error Resume Next
Err = 1
While Err <> 0
    Err = 0
    If ConnectStr <> "" Then
        Set MyDB = OpenDatabase(NameStr, dbDriverNoPrompt, False,
ConnectStr)
    Else
        Set MyDB = OpenDatabase(NameStr)
    End If
    Debug.Print Err; ": "; Error$
    If Err = 3059 Then
        NameStr = MyDBName
        ConnectStr = ""
    Else
        If Err = 3024 Then
            End
        Else
            NameStr = MyDB.Name
            ConnectStr = MyDB.Connect
        End If
    End If
    If Err <> 0 Then Pause 5
Wend
On Error GoTo 0
If ConnectStr <> "" Then
    SaveSetting App.EXEName, "CONNECTION", "CSTR", ConnectStr
    SaveSetting App.EXEName, "CONNECTION", "NSTR", NameStr
End If

' at this point, we can do queries, etc.  Don't forget to add
dbSQLPassThrough, or your SQL will run dog-slow!

Thread
connection to DAO.connection fails usin myodbcrobert rottermann27 Nov
  • RE: connection to DAO.connection fails usin myodbcEd Carp27 Nov
    • Re: connection to DAO.connection fails usin myodbcrobert rottermann27 Nov
  • Re: connection to DAO.connection fails usin myodbcDennis Salguero28 Nov
Re: connection to DAO.connection fails usin myodbcDennis Salguero28 Nov