2015-05-21 44 views
0

到SQL所以我想我的SQL數據庫連接到我的VB項目,但它給了我這個錯誤:錯誤連接用VB

Error Connecting to Database : Authentication to host "for user" using method 'mysql_native_password' failed with message : Acces denied for user "@'N56VB' (using password : NO)

N56VB是我的電腦

UPDATE錯誤至極我現在得到是:類型的第一次機會異常

'System.ArgumentException' occurred in System.Data.dll

Additional information: Keyword not supported.

If there is a handler for this exception, the program may be safely continued

我不知道該怎麼辦了這將是一個愚蠢的我猜,很容易對我,我一個小白:( 我希望有人知道這個問題的

Imports MySql.Data.MySqlClient 
Imports System.Data.Sql 
Imports System 
Imports System.Data 
Public Class NieuweItems 
    Public dbconn As New MySqlConnection("Data Source=localhost;user id=root;password=;database=gip;") 
    Dim conn As New MySqlConnection 
    Private Sub btn_return_Click(sender As Object, e As EventArgs) Handles btn_return.Click 
     Me.Close() 
     SalesApplication.Show() 
    End Sub 
    Private Sub btn_inlezen_Click(sender As Object, e As EventArgs) Handles btn_inlezen.Click 
     Dim sqlCommand As New MySqlCommand 
     Dim SQLConnection As MySqlConnection = New MySqlConnection 
     Dim strStockSQL As String 
     SQLConnection.ConnectionString = "Data Source= localhost ;user id = root'@'localhost; password = ;database=gip;table=stock;" 
     Try 
      conn.Open() 
      strStockSQL = "INSERT INTO Barcode " & txtBarcode.Text & "INSERT INTO Naam_Product" & txtNaam.Text & "INSERT INTO Verkoopprijs" & txtVP.Text 
      sqlCommand.ExecuteNonQuery() 
      SQLConnection.Close() 
      conn.Close() 
     Catch myerror As MySqlException 
      MessageBox.Show("Error Connecting to Database: " & myerror.Message) 
     Finally 
      conn.Close() 
     End Try 
    End Sub 

End Class 
+0

http://www.connectionstrings.com/mysql-connector-net-mysqlconnection/ – Plutonix

回答

0

我認爲錯誤發生在「btn_inlezen_Click」事件處理程序內?我認爲發生的事情是你聲明瞭一個新的空MySqlConnection,在你的Try塊中打開連接,然後你設置ConnectionString。由於MySqlConnection被聲明爲不帶任何參數,因此它可能試圖將N56VB用作用戶帳戶,並且這對MySQL數據庫沒有任何權限。

因此,在打開連接之前設置連接字符串。

+0

我想,現在我得到這個:類型System.ArgumentException「未處理的異常出現在system.data.dll 附加信息:不支持關鍵字。 – Nordin

+0

然後你的連接字符串出錯了;請訪問http://www.connectionstrings.com/並確保您的字符串具有正確的語法。我會質疑table參數,以及如何將用戶標識傳入字符串。 – markp3rry