I am building a Windows Store application who is intended to interact with a MySql database located at a server in my local network. 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; although i can get a successful connection with a different Win32 app, who has the same connection string. 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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.