Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法连接,vb.net&;mysql_Mysql_Vb.net_Connection String - Fatal编程技术网

无法连接,vb.net&;mysql

无法连接,vb.net&;mysql,mysql,vb.net,connection-string,Mysql,Vb.net,Connection String,因此,我正在使用vb.net和mysql开发我的第一个数据库。我遵循了一些关于如何连接两者的指南(例如)。但是,当我运行代码时,我会收到错误消息“无法连接到数据库”。这是我遇到问题的代码。请注意,我已经遵循了字母指南(连接字符串除外)。我相信我的问题就在于此,但我并不乐观。此外,我的数据库在这一点上非常基本,只是简单地命名为“数据库” 请尝试显示该消息 Try cnx.Open() Catch ex as Exception If ex.InnerException IsNot

因此,我正在使用vb.net和mysql开发我的第一个数据库。我遵循了一些关于如何连接两者的指南(例如)。但是,当我运行代码时,我会收到错误消息“无法连接到数据库”。这是我遇到问题的代码。请注意,我已经遵循了字母指南(连接字符串除外)。我相信我的问题就在于此,但我并不乐观。此外,我的数据库在这一点上非常基本,只是简单地命名为“数据库”

请尝试显示该消息

Try
    cnx.Open()
Catch ex as Exception
    If ex.InnerException IsNot Nothing Then
        MessageBox.Show(ex.InnerException.Message)
    Else
        MessageBox.Show(ex.Message)
    End Try
Finally
    If cnx.State = ConnectionState.Open Then cnx.Close()
End Try
或者,您也可以使用断点并调试代码,以获得适当的堆栈跟踪,从而为您提供更详细的信息

此外,您可能需要检查连接字符串并确保其正确无误


当DB可以告诉您问题所在时,千万不要将固定/无用的字符串作为错误消息输出:
catch ex。。。show(例如ToString())
我认为您需要在connectionstring中指定更多细节。看看这个网站,寻找更好的例子:我运行了你的代码,得到了以下消息:“拒绝用户'@localhost'的访问”(使用密码:(否)”如果您的数据库受密码保护,则需要在连接字符串中随用户ID一起提供。这意味着您的用户ID和密码不正确或根本没有提供。这意味着您的连接字符串不正确。请查看提供的链接“MySQL连接字符串”,然后选择您需要的链接.
Try
    cnx.Open()
Catch ex as Exception
    If ex.InnerException IsNot Nothing Then
        MessageBox.Show(ex.InnerException.Message)
    Else
        MessageBox.Show(ex.Message)
    End Try
Finally
    If cnx.State = ConnectionState.Open Then cnx.Close()
End Try