Excel VBA and sqlite : personnal dlls path

Hello,

i'm working on a portable app with Excel VBA and sqlite, i would like to specify a personal path for dlls in the connection String. can you help me with that

' Chemins personnalisés vers les DLLs et Base de données
Private Const DLL_SQLITE As String = "D:\sqliteVBA\DLLs\sqlite3.dll"
Private Const DLL_OLEDB As String = "D:\sqliteVBA\DLLs\sqlite3odbc.dll"
Private Const DB_PATH As String = "D:\sqliteVBA\Databases\MyDB.sqlite"
Private Const LIBRARIES_PATH As String = "D:\sqliteVBA\Libraries"

' Déclaration API Windows pour charger les DLLs
Private Declare PtrSafe Function LoadLibraryA Lib "kernel32" (ByVal lpLibFileName As String) As LongPtr
Private Declare PtrSafe Function GetLastError Lib "kernel32" () As Long

Public Function ConnexionSQLite() As ADODB.Connection
Dim conn As ADODB.Connection
Dim errMsg As String

' Vérifier que les DLLs sont chargées
If Not ChargerDLLPersonnalisees() Then
    Debug.Print "ERREUR : Impossible de charger les DLLs"
    Set ConnexionSQLite = Nothing
    Exit Function
End If

Set conn = New ADODB.Connection

' Chaîne de connexion avec ResolutionPath
conn.ConnectionString = "Driver={SQLite3 ODBC Driver};" & _
                        "Database=" & DB_PATH & ";" & _
                        "ResolutionPath=" & LIBRARIES_PATH & ";" & _
                        "NoTXN=1;" & _
                        "StepAPI=1;" & _
                        "Timeout=10;" & _
                        "SyncPragma=NORMAL;" & _
                        "NoWCHAR=0"

On Error Resume Next
conn.Open

If Err.Number <> 0 Then
    errMsg = "Erreur de connexion : " & Err.Description
    Debug.Print errMsg
    MsgBox errMsg, vbCritical
    Set ConnexionSQLite = Nothing
Else
    Debug.Print "Connexion réussie"
    Set ConnexionSQLite = conn
End If

On Error GoTo 0

End Function

0 answers