2012-01-02 71 views
0

我嘗試讓用戶登錄到我在vb.net中使用應用程序的數據庫用戶表在MySQL創建vb.net使用mysql數據庫

我聽說,通常的方式做,這是一個應用程序的應用程序登錄只有一個名爲「[my_app_name]」的MySQL用戶具有相關權限。然後,我的應用程序使用它自己的用戶表來控制對應用程序的訪問,並使用一個MySQL用戶訪問數據庫。但我不知道該怎麼做,有人可以幫助我。這一切都是新鮮事。

感謝

+1

你不知道該怎麼做?創建一個應用程序或設置數據庫調用或創建一個MySQL用戶或創建一個MySQL數據庫?對你試過的東西和你需要幫助的東西稍微具體一點。 – Robert 2012-01-02 21:24:01

+0

問題是我有一個表稱爲用戶,其中包含所有我的用戶的用戶名和密碼,但他們不能登錄,直到我進入mysql工作臺服務器管理,並讓他們直接訪問數據庫,但有人告訴我,而不是做這個,通常的做法是讓一個名爲「[my_app_name]」的MySQL用戶擁有相關權限。然後,我的應用程序使用它自己的用戶表來控制對應用程序的訪問,並使用一個MySQL用戶訪問數據庫。 這就是我需要幫助,讓應用程序使用自己的用戶表,而無需直接訪問。 – user1012135 2012-01-02 21:40:06

回答

0

打開的MySQL Workbench和向第一屏幕右下方的「服務器管理」一欄下,你會看到「管理安全性」。點擊它。在左側的菜單中,您將看到「用戶和權限」。點擊它。您會看到一個顯示「添加帳戶」的按鈕,點擊該按鈕後,您可以創建新用戶。在Schema Privileges選項卡中,您可以修改用戶的權限。

您在此處創建的用戶可以在連接字符串中使用。這是來自我的一個應用程序的示例MySQL連接字符串。下面的連接字符串中的用戶名修復爲「修復」和「限制與主機匹配的連接性」爲「%」的「登錄名:」。

「服務器= 10.0.0.113; UID =修復; PWD = '密碼& 92';數據庫=修」

我希望這有助於。祝你有美好的一天。

1

如果您製作的登錄表單將檢查用戶和他們在MySQL數據庫上的密碼的身份驗證,請按照我爲自己的登錄表單編寫的代碼進行操作。

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click 

    Dim conn As MySqlConnection 

     'Connect to the database using these credentials 
     conn = New MySqlConnection 
    conn.ConnectionString = "your server goes here; user id=userid goes here; password=self explanatory; database=the database where the credential information is located" 

     'Try and connect (conn.open) 
     Try 
      conn.Open() 

     Catch myerror As MySqlException 'If it fails do this... (i.e. no internet connection, etc.) 
     MsgBox("Error connecting to database. Check your internet connection.", MsgBoxStyle.Critical) 
     End Try 


     'MySQL query (where to call for information) 
     Dim myAdapter As New MySqlDataAdapter 

     'Tell where to find the file with the emails/passes stored 
    Dim sqlquery = "SELECT * FROM your database with info WHERE Email = '" & txtEmail.Text & "' AND Password = '" & txtPassword.Text & "'" 
     Dim myCommand As New MySqlCommand 
     myCommand.Connection = conn 
     myCommand.CommandText = sqlquery 

     'Start query 
     myAdapter.SelectCommand = myCommand 
     Dim myData As MySqlDataReader 
     myData = myCommand.ExecuteReader 

     'See if the user exists 
     If myData.HasRows = 0 Then 
     MsgBox("Invalid email address or password.", MsgBoxStyle.Critical) 

     'Insert your settings change here. (i.e. My.Settings.LoggedIn = False) 

     Else 
     MsgBox("Logged in as " & txtEmail.Text & ".", MsgBoxStyle.Information) 

     'Another settings change: My.Settings.LoggedIn = True 

      Me.Close() 'close the login form 

    End If 

請務必更改控件名稱並添加設置。