2012-01-02 74 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 

请务必更改控件名称并添加设置。