簡體   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