Solved

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

Posted on 2003-10-22
4
501 Views
Last Modified: 2008-07-24
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
0
Comment
Question by:juanfigs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

by:NeXus
ID: 9605262
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



0
 

Author Comment

by:juanfigs
ID: 9605370
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
0
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 9607073
Under References add Microsoft Remote Data Object 2.0

HTH
dragontooth

0
 

Accepted Solution

by:
latin79 earned 150 total points
ID: 9610003
You can try this and let me know.

This code will display the records in a msgbox you can use that just to testit for now.

You have to add the adodb reference      

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
                                      Handles MyBase.Load    
        Dim conn As ADODB.Connection
        Dim rs As ADODB.Recordset
        conn = New ADODB.Connection()
        rs = New ADODB.Recordset()
        conn.Open("Driver={MySQL ODBC 3.51 Driver};
                          UID=username;server=servername;database=databasename")
        rs.Open("select * from table", conn, ADODB.CursorTypeEnum.adOpenDynamic,
                      ADODB.LockTypeEnum.adLockOptimistic)
        Do While Not rs.EOF
            MsgBox(rs.Fields(1).Value)
            rs.MoveNext()
        Loop
        rs.Close()
        rs = Nothing
        conn.Close()
        conn = Nothing
end sub
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question