System.Data.SqlClient.SqlConnection“异常:未知数据包类型74”

时间:2015-03-11 19:55:50

标签: c# mysql mono sqlconnection

我正在尝试使用System.Data.SqlClient.SqlConnection连接到MySQL数据库,并且我收到“异常:未知数据包类型74”。

这在技术上是通过Unity3D 4,虽然我不确定这与问题有关。*它似乎是一个C#问题,而不是单声道问题 - 即使错误是在单声道模块中生成的。我错了。

我见过...... Can't connect to remote SQL server in C# ......但它似乎也不相关。

  • 不,数据库登录信息不会成为游戏代码的一部分,因此不会被黑客攻击。但由于超出此问题范围的原因,我更愿意直接连接而不是通过套接字代理连接。

--- --- SQLConnect.cs

using UnityEngine;
using System.Collections;
using System.Net;
using System.Data.SqlClient;

namespace dataVis{

    public class SQLConnect : MonoBehaviour {

        public SqlConnection sqlConnection1;

        private string _server          = "ec2-54-165-xxx-xxx.compute-1.amazonaws.com";
        private string _port            = "3306";
        private string _db              = "xxxxdb";      
        private string _u               = "xxxuser";
        private string _p               = "xxxpass";
        private string _persistSecurity = "true";

        // Constructor ------------------------------
        public SQLConnect()
        {
            SetConnection();
        }//constructor

        private void SetConnection()
        {
            string connectionString = (
                                        "server=tcp:" + _server + ", " + _port + ";" +
                                        //"server=" + _server + ", " + _port + ";" +
                                        "Database=" + _db + ";" +  
                                        "UID=" + _u + ";" +
                                        "Password=" + _p + ";" +
                                        "PersistSecurityInfo=" + _persistSecurity
                                        );

            //Connecting to remote Microsoft SQL Database Server
            sqlConnection1 = new SqlConnection(connectionString);

            Debug.Log("(from SQLConnect)sqlConnection1 =" + sqlConnection1 + "; opening...");

            sqlConnection1.Open(); // error ocurrs here. 

            Debug.Log("Open.");

        }// SetConnection

    }//class

}//namespace

--- main.cs ---

using UnityEngine;
using System.Collections;
using System.Net;
using System.Data.SqlClient;
using dataVis;

public class Main : MonoBehaviour {

    public SQLConnect CONN;

    // Use this for initialization

    void Start () 
    {
        Debug.Log("Starting main...creating new SQL connection");
        CONN = this.gameObject.AddComponent<SQLConnect>();
        //CONN.test();
    }//start

    // Update is called once per frame
    void Update () 
    {
    }//Update

}//class

---完全错误---

Exception: Unknown packet type 74
Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacketHeader ()
Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacket ()
Mono.Data.Tds.Protocol.TdsComm.GetByte ()
Mono.Data.Tds.Protocol.Tds.ProcessSubPacket ()
Mono.Data.Tds.Protocol.Tds.NextResult ()
Mono.Data.Tds.Protocol.Tds.SkipToEnd ()
Mono.Data.Tds.Protocol.Tds70.Connect(Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters)
Mono.Data.Tds.Protocol.Tds80.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters)
System.Data.SqlClient.SqlConnection.Open ()
UnityEngine.GameObject:AddComponent()
Main:Start() (at Assets/Scripts/Main.cs:14)

1 个答案:

答案 0 :(得分:1)

SqlClient用于连接Microsoft SQL Server,而不是MySQL。我认为MySQL Connector/NET是你所寻找的领域。