无法连接到网络mysql数据库

时间:2013-12-27 18:57:08

标签: mysql windows-store

我正在构建一个Windows应用商店应用程序,该应用程序旨在与位于我本地网络中的服务器的MySql数据库进行交互。 我正在使用MySQL连接器/ net RT进行连接(这对我的测试localhost DB起作用),问题是由于某种原因我无法连接到网络数据库;虽然我可以与另一个具有相同连接字符串的Win32应用程序成功连接。 我禁用了防火墙,我在主机上创建了一个新用户,可以从我的AP等访问。有人可以告诉我我做错了什么吗?

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();
}

//例外: 无法打开连接

1 个答案:

答案 0 :(得分:0)

这是我连接的方式。希望它有助于

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