Link to home
Start Free TrialLog in
Avatar of ahpaul
ahpaul

asked on

Help with GetPrivateProfileString & MySQL Connection

Hi, I'm having problem using GetPrivateProfileString and I'm using MySQL ODBC

Dim fName As String
    fName = App.Path & "\db.ini"
   
    If Len(Dir(fName)) = 0 Then
        WritePrivateProfileString "MySQL", "Server", "192.168.0.8", fName
        WritePrivateProfileString "MySQL", "Port", "3306", fName
        WritePrivateProfileString "MySQL", "User", "root", fName
        WritePrivateProfileString "MySQL", "Password", "", fName
    End If
   
    Dim Server As String
    Dim Port As String
    Dim User As String
    Dim Password As String
   
    Server = String(20, " ")
    Port = String(20, " ")
    User = String(20, " ")
    Password = String(20, " ")
   
    GetPrivateProfileString "MySQL", "Server", "192.168.0.8", Server, Len(Server), fName
    GetPrivateProfileString "MySQL", "Port", "3306", Port, Len(Port), fName
    GetPrivateProfileString "MySQL", "User", "root", User, Len(User), fName
    GetPrivateProfileString "MySQL", "Password", "", Password, Len(Password), fName

    Server = Trim$(Server)
    Port = Trim$(Port)
    User = Trim$(User)
    Password = Trim$(Password)

Public Sub Connect(ByVal Server As String, ByVal Port As Integer, ByVal User As String, ByVal Password As String)
    With adoCon
        On Error GoTo ErrHld
       
        .Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=server;PORT=" & Port & ";DATABASE=toms;USER=" & User & ";PASS=" & Password & ";OPTION=3;"
        .CursorLocation = adUseClient
       
    End With

ErrHld:
    adoError
End Sub


I got problem connecting using these string, because the string here are trailing with empty space, even I trim it.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial