[英]I'm trying to connect to mysql with vb 2010 express, Access denied
i have already read a ton of posts about connecting vb 2010 express to Mysql in Wamp, but none solved my problem :P. 我已经阅读了很多有关在Wamp中将vb 2010 express连接到Mysql的帖子,但是没有一个解决我的问题的:P。 The thing is that i have a local Mysql server running, to which i do connect with no problems in PHP and MySQL Workbench, but when i tried to connect with vb 2010 express i found out i had to Import the connector and then build the code accordingly.
事实是,我正在运行一个本地Mysql服务器,并且确实可以连接到PHP和MySQL Workbench,但是当我尝试与vb 2010 Express连接时,我发现必须导入连接器,然后构建代码相应地。
I think my code is ok, but still getting the message "WindowsApplication1.vshost.exe Error: 0 : Access denied for user 'root'@'localhost' (using password: YES)" 我认为我的代码还可以,但是仍然收到消息“ WindowsApplication1.vshost.exe错误:0:拒绝用户'root'@'localhost'的访问(使用密码:是)”
Here's the code: 这是代码:
Private Sub CheckPayments()
Try
myPassword = ""
myConnstr = "Server=localhost;Database=kiosk;Uid=root;Pwd=myPassword"
myQuery = "select * from products where deleted = 0"
Dim myConn As New MySqlConnection(myConnstr)
Dim myDa As New MySqlDataAdapter(myQuery, myConn)
If myDa.Fill(myDs) Then ' 1 significa que a ligação foi efetuada com sucesso
mysqldump.DataSource = myDs.Tables(0)
End If
myConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Stuck in project with this error, need help quick !! 卡在此错误的项目中,需要快速帮助! Thanks in advance for any help you can give me :)
预先感谢您可以给我的任何帮助:)
BR, Carlos Mendes BR,卡洛斯·门德斯
hope this helps out someone who needs to connect VB2010 Express to MySQL. 希望这对需要将VB2010 Express连接到MySQL的人有所帮助。
This code displays MySQL data in a DataGridView object. 此代码在DataGridView对象中显示MySQL数据。 Connections problem solved :).
连接问题已解决:)。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=<your db>;User ID=<your user>;Password=<your password>;")
Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM <your table>", con)
Dim ds As DataSet = New DataSet()
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
con.Open()
DataAdapter1.SelectCommand = sql
DataAdapter1.Fill(ds, "<DataGridView table name>")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "<DataGridView table name>"
con.Close()
End Sub
You should Import Connecter, is better and good way with out any trouble! 您应该导入连接器,这是没有任何麻烦的更好的好方法!
mysql-connector-net-6.4.5-noinstall mysql-connector-net-6.4.5-noinstall
Then go to Project -> Add Reference -> TAB-Browse 然后去项目->添加参考-> TAB浏览
Browse where you save "mysql-connector-net-6.2.2" 浏览保存“ mysql-connector-net-6.2.2”的位置
Select only mysql.data.dll 仅选择mysql.data.dll
Then use your Connection command to connect WAMP MYSQL! 然后使用您的Connection命令连接WAMP MYSQL! Thats It..
而已..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.