我正在尝试使用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)