VB.NET 到 MySQL 数据库的 SqlConnection

VB.NET SqlConnection to MySQL Database

尽管我确实阅读了大量 Whosebug 帖子并查看了很多教程网站,但我无法让我的代码正常工作。

我想使用 sqlBulkCopy。因此我需要一个 'SqlConnection' class 的实例。我有一个 MySQL 数据库 运行,我完全可以打开与 'MySqlConnection' class.

的连接

我已经尝试了几种方法来使 SqlConnection 正常工作。

MySqlConnection(有效):

  Dim a = "Server=localhost;Initial Catalog=hauptdatenbank;User Id=johnny;Password=123456;"

  Using cn As New MySqlConnection(a)
     cn.Open()
  End Using

SqlConnection(不起作用):

  Dim a = "Server=localhost;Initial Catalog=hauptdatenbank;User Id=johnny;Password=123456;"

  Using cn As New SqlConnection(a)
     cn.Open()
  End Using

抛出以下 SqlException:

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)

SqlBulk 仅适用于 SQL 数据库。 MySqlBulkLoader 用于 MySQL 数据库。

感谢评论!

进口MySql.Data.MySqlClient

模块连接

Public str1 As String = "data source=localhost;user id= root;password=;database= parisbugdb;"

模块结束

If Len(Trim(PassBox.Text)) = 0 Then
    AlertLabel.Visible = True
    AlertLabel.Text = "Password required!"
    PassBox.SelectAll()
    PassBox.Focus()
    Return
End If

con.Open()
Dim Sql = "SELECT * FROM userx WHERE username ='" & UserBox.Text & "' AND password = '" & PassBox.Text & "'"
scmd = New MySqlCommand(sql, con)
Dim sdr As MySqlDataReader = scmd.ExecuteReader


Try
    If sdr.Read = False Then

        AlertLabel.Visible = True
        AlertLabel.Text = "Login denied!"
        con.Close()
    Else

        UserBox.Clear()
        PassBox.Clear()
        UserBox.Focus()
        Me.Hide()
        Dashboard.Show()
    End If


Catch ex As Exception
    MsgBox(ex.ToString())
End Try

结束子