Link to home
Start Free TrialLog in
Avatar of juanfigs
juanfigs

asked on

How do I connect to MySql on a linux server with VB.NET?

How do I connect to MySql on a linux server with VB.NET and how to connect to an imap server in linux with vb.net
Avatar of NeXus
NeXus

First install a MYSql driver on your windows box...

Then work out what your DSN (Data Source Name) is...
then heres some code...


Private Sub cmdConnectMySQL_Click()

Dim cnMySql As New rdoConnection
Dim rdoQry As New rdoQuery
Dim rdoRS As rdoResultset

' set up a remote data connection using the
' MySQL ODBC driver.
' change the connect string with your username,
' password, server name and the database you
' wish to connect to.

cnMySql.CursorDriver = rdUseOdbc
cnMySql.Connect = "uid=YourUserName;pwd=YourPassword;server=YourServerName;" & _
    "driver={MySQL ODBC 3.51 Driver};database=YourDataBase;dsn='';"
cnMySql.EstablishConnection

' set up a remote data object query
' specifying the SQL statement to run.

With rdoQry
    .Name = "selectUsers"
    .SQL = "select * from user"
    .RowsetSize = 1
    Set .ActiveConnection = cnMySql
    Set rdoRS = .OpenResultset(rdOpenKeyset, rdConcurRowVer)
End With
   
' loop through the record set processing the
' records and fields.

Do Until rdoRS.EOF
    With rdoRS

      ' your code to process the fields
      ' to access a field called username you would
      ' reference it like !username
           
        rdoRS.MoveNext
    End With
Loop

' close record set
' close connection to the database

rdoRS.Close
cnMySql.Close

End Sub

also here:
http://www.cgi-interactive.co.uk/vb6mysql.zip



Avatar of juanfigs

ASKER

And what components I need or what else because I paste all that and I put the username, hostname and everything and I still have errors.

rdoconnection not defined
rdoquery not defined
rdoresultset not defined
Avatar of Tommy Kinard
Under References add Microsoft Remote Data Object 2.0

HTH
dragontooth

ASKER CERTIFIED SOLUTION
Avatar of latin79
latin79

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