连接到wampserver MySQL可以在PHP中工作,但不能在vb.NET中工作
我有一个运行MySQL的本地wampserver。我已通过PHP成功连接到它:连接到wampserver MySQL可以在PHP中工作,但不能在vb.NET中工作,php,mysql,vb.net,visual-studio-2010,wamp,Php,Mysql,Vb.net,Visual Studio 2010,Wamp,我有一个运行MySQL的本地wampserver。我已通过PHP成功连接到它: <?php $servername = "localhost"; $username = "pyramid"; $password = "pyramid"; try { $conn = new PDO("mysql:host=$servername;dbname=test", $username, $password); // set the PDO error mode to excepti
<?php
$servername = "localhost";
$username = "pyramid";
$password = "pyramid";
try {
$conn = new PDO("mysql:host=$servername;dbname=test", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
经过5到10秒的长时间等待后,我得到“系统找不到指定的文件”
两者都有完全相同的用户名、密码服务器和数据库名称,但vb.NET仍然拒绝连接
我已经尝试了几乎所有我能想到的,并且用尽了我的选择。你能解释一下吗?你需要下载MySQL connector for.NET Framework(),然后在你的项目中引用.DLL
Imports MySqL.Data.MySqlClient
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim ConnectionString As String
Dim SQLCon As MySqlConnection
ConnectionString = "Server=localhost;Database=test;Uid=pyramid;Pwd=pyramid"
SQLCon = New MySqlConnection(ConnectionString)
Try
SQLCon.Open()
Catch ex As Exception
If ex.InnerException IsNot Nothing Then
MessageBox.Show(ex.InnerException.Message)
Else
MessageBox.Show(ex.Message)
End If
Finally
If SQLCon.State = ConnectionState.Open Then SQLCon.Close()
End Try
End Sub
End Class
首先确保安装了MySQL Connector/NET。然后尝试从VisualStudio连接,从SQL Server对象资源管理器连接以检查连接。请阅读以下内容:现在已经完全解决了。非常感谢你!欢迎!!;)按下橙色向上箭头:)并解释您是如何解决的,供其他人学习:)
Imports MySqL.Data.MySqlClient
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim ConnectionString As String
Dim SQLCon As MySqlConnection
ConnectionString = "Server=localhost;Database=test;Uid=pyramid;Pwd=pyramid"
SQLCon = New MySqlConnection(ConnectionString)
Try
SQLCon.Open()
Catch ex As Exception
If ex.InnerException IsNot Nothing Then
MessageBox.Show(ex.InnerException.Message)
Else
MessageBox.Show(ex.Message)
End If
Finally
If SQLCon.State = ConnectionState.Open Then SQLCon.Close()
End Try
End Sub
End Class