开发者

trying to connect mysql with vb.net

开发者 https://www.devze.com 2022-12-23 07:40 出处:网络
I\'ve found this at connection strings.com http://connectionstrings.c开发者_如何转开发om/mysql

I've found this at connection strings.com http://connectionstrings.c开发者_如何转开发om/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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消