[英]Cannot connect to a network mysql database
I am building a Windows Store application who is intended to interact with a MySql database located at a server in my local network. 我正在构建一个Windows Store应用程序,该应用程序旨在与位于本地网络中服务器上的MySql数据库进行交互。 I am using MySQL connector/net RT to connect(which works on my testing localhost DB), the problem is that for some reason i cannot connect to the network database; 我正在使用MySQL连接器/ net RT进行连接(可在我的测试localhost DB上运行),问题是由于某种原因我无法连接到网络数据库; although i can get a successful connection with a different Win32 app, who has the same connection string. 尽管我可以成功连接到具有相同连接字符串的其他Win32应用程序。 i disabled the firewall, i created a new user on the host to access from my AP, etc. Can somebody tell me what am I doing wrong? 我禁用了防火墙,在主机上创建了一个新用户以从我的AP进行访问,等等。有人可以告诉我我在做什么错吗?
C# C#
using MySQL.Data.MySqlClient;
using Windows.UI.Popups;
MySqlConnection connection = new MySqlConnection("server=1.1.1.1;port=3306;database=mydb;uid=user;password=****;");
try{
connection.Open();
connection.Close();
}
catch (MySqlException e){
MessageDialog md = new MessageDialog(e.ToString());
md.ShowAsync();
}
//Exception: failed to Open Connection //例外:无法打开连接
This is how I connect. 这就是我的联系方式。 Hope it Helps 希望能帮助到你
Imports MySql.Data.MySqlClient
Public Class ClassMySqlConnect
Public Shared SQLConnect As String = "Server=YOURSERVERADDRESS; User Id=YOURID; Password=YOURPASSWORD;Database=YOURDATABASENAME"
Public Function connect(ByVal PlayerID As String) As String
Dim SQLConnection = New MySqlConnection
SQLConnection.ConnectionString = SQLConnect
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
'Return "Sucessfully Connected to MySql Database"
Else
SQLConnection.Open()
' Return "Connection is closed"
End If
Catch ex As Exception
' Return ex.ToString()
End Try
Dim SQLStatement As String = "INSERT INTO Toons (PlayerID) Values('" + PlayerID + "')"
Dim cmd As New MySqlCommand
With cmd
.CommandText = SQLStatement
.CommandType = CommandType.Text
.Connection = SQLConnection
.ExecuteNonQuery()
End With
Return "successfully saved"
End Function
End Class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.