Hi,

How to connect visual basic program with mysql database?I need a sample program of retrieving the data and also inserting the data into the table using mysql database..........I dont have any idea.....


please help me .......

Regards,
Santhanalakshmi.

1. Install first MwSQL ODBC Connecto 5.1r, you can download it from MySQL website.

2. Provide this code:

Dim conn As New Odbc.OdbcConnection
Dim connString As String = "DRIVER={MySQL ODBC 5.1 Driver};" _
                        & "SERVER= Your Server Name;" _
                        & "PORT=3306;" _
                        & "DATABASE=Your Database Name;" _
                        & "UID=Your MySQL User ID;PWD=Your MySQL password; OPTION =3;"

        If conn.State = ConnectionState.Open Then conn.Close()

        With conn
                .ConnectionString = connString
                .Open()
         End With

1. Install first MwSQL ODBC Connecto 5.1r, you can download it from MySQL website.

2. Provide this code:

Dim conn As New Odbc.OdbcConnection
Dim connString As String = "DRIVER={MySQL ODBC 5.1 Driver};" _
                        & "SERVER= Your Server Name;" _
                        & "PORT=3306;" _
                        & "DATABASE=Your Database Name;" _
                        & "UID=Your MySQL User ID;PWD=Your MySQL password; OPTION =3;"

        If conn.State = ConnectionState.Open Then conn.Close()

        With conn
                .ConnectionString = connString
                .Open()
         End With

Thanks ,its working fine on the local machine.But i am facing a different problems,when i am connecting a mysql database remotely from my local machine

CODE:

Private Sub gen_Click()
Dim cn1 As New ADODB.Connection
Dim generate As New ADODB.Command
Dim rs1 As New ADODB.Recordset


Set cn1 = New ADODB.Connection

cn1.ConnectionString = "driver={MySQL ODBC 3.51 Driver};server=10.93.199.253;database=org;port=3306;user=root;Option=3"
cn1.Open

With generate
.ActiveConnection = cn1
.CommandType = adCmdText
.CommandText = "select ugid from user"
End With

Set rs1 = generate.Execute
Open "C:\org.txt" For Output As #2
While Not rs1.EOF
Print #2, rs1.Fields(0);
rs1.MoveNext
Wend

End Sub


The Following Error occur:

Runtime error '-2147467259(80004005)'
[Microsoft][ODBC Driver Manager]Data Source name not found and no default driver specified.

One more doubt:
For accessing mysql database remotely,we need to give ODBC connection.Then what should be filled....
(1)Data Source Name
(2)Server
(3)user
(4)password

I installed mysql-odbc-connector 5.1.5.Please help me........

thanks,
santhanalakshmi.

On the remote machine... Did you create the ODBC DSN so that it pointed to the machine with the DB? Because that is the gist of the message.

On the remote machine... Did you create the ODBC DSN so that it pointed to the machine with the DB? Because that is the gist of the message.

hi,
I have created ODBC DSN on the remote machine(windows xp only).
(1)IP address is 10.93.199.257
(2)I given DSN name as :org1
(3)Server:localhost
(4)user:root
(5)no password
(6)database:org(located in the remote machine)

please solve me this error.thanks in advance


santhanalakshmi

Check www.connectionstrings.com to see if your connection string is in the proper format. Then when you created your DSN did you test it? Did it work? Test it again to see if it is working. If not, is the service running on your computer?

hi,
I have created ODBC DSN on the remote machine(windows xp only).
(1)IP address is 10.93.199.257
(2)I given DSN name as :org1
(3)Server:localhost
(4)user:root
(5)no password
(6)database:org(located in the remote machine)

please solve me this error.thanks in advance


santhanalakshmi

If your Database is located in a remote machine i.e. 10.93.199.257 then your "Server" must be "Server=10.93.199.257". so your connection must be:

"Driver={MySQL ODBC 5.1 Driver};Server = 10.93.199.257;Port 3306; UID = root; Option 3"

If your Database is located in a remote machine i.e. 10.93.199.257 then your "Server" must be "Server=10.93.199.257". so your connection must be:

"Driver={MySQL ODBC 5.1 Driver};Server = 10.93.199.257;Port 3306; UID = root; Option 3"

What server you are using with your mysql.?is it apache.? If it is then.? you have to create a virtual host settings on the apache where your database is located so that all other machines on the network will see it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.