繁体   English   中英

VB.NET SqlConnection到MySQL数据库

[英]VB.NET SqlConnection to MySQL Database

尽管我确实阅读了很多stackoverflow的文章,还检查了许多教程网站,但我的代码无法正常工作。

我想使用sqlBulkCopy。 因此,我需要'SqlConnection'类的实例。 我有一个正在运行的MySQL数据库,打开与“ MySqlConnection”类的连接完全没有问题。

我尝试了几种方法来使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:

建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 服务器未找到或无法访问。 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

SqlBulk仅适用于SQL DB。 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

结束子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM