user225269
user225269

Reputation: 10913

trying to connect mysql with vb.net

I've found this at connection strings.com http://connectionstrings.com/mysql

Do I need to download connector-net from this site: http://dev.mysql.com/downloads/connector/net/

I recycled the code that I used in connecting vb.net with ms sql:

Imports system.data.sqlclient

idnum = TextBox1.Text
    lname = TextBox2.Text
    fname = TextBox3.Text
    skul = TextBox4.Text

    Using sqlcon As New SqlConnection("Server=localhost;Port=3306;Database=testing;Uid=root;Pwd=mypassword;")

        sqlcon.Open()
        Dim sqlcom As New SqlCommand()
        sqlcom.Connection = sqlcon

        sqlcom.CommandText = "INSERT INTO [student](ID, LASTNAME, FIRSTNAME, SCHOOL) VALUES (@ParameterID, @ParameterLastName, @ParameterFirstName, @ParameterSchool)"

        sqlcom.Parameters.AddWithValue("@ParameterID", TextBox1.Text)
        sqlcom.Parameters.AddWithValue("@ParameterLastName", TextBox2.Text)
        sqlcom.Parameters.AddWithValue("@ParameterFirstName", TextBox3.Text)
        sqlcom.Parameters.AddWithValue("@ParameterSchool", TextBox4.Text)

        sqlcom.ExecuteNonQuery()

    End Using

But I get this error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Please help, what solutions would you recommend to this problem?

Upvotes: 0

Views: 2979

Answers (1)

Leniel Maccaferri
Leniel Maccaferri

Reputation: 102408

This article should get you started:

The VB.NET-MySQL Tutorial – Part 3

The article uses MySQL Connector for .NET...

MySQL Connector/NET is available for download at http://dev.mysql.com/downloads/connector/net/. Download the version that includes an installer to your local hard-drive and extract the Zip file.

Double-click the installer file to begin the installation process. Perform a complete install to the default directory.

In the code you have:

conn = New MySqlConnection()
conn.ConnectionString = "server=" & txtServer.Text & ";" _
& "user id=" & txtUsername.Text & ";" _
& "password=" & txtPassword.Text & ";" _
& "database=in_out"

Check this out too:

Accessing MySQL Database from my VB.NET 2008 Project

Upvotes: 1

Related Questions