System.Data.SqlClient.SqlConnection“异常:未知数据包类型 74”
System.Data.SqlClient.SqlConnection “Exception: Unknown packet type 74”
我正在尝试使用 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)
SqlClient 用于连接到 Microsoft SQL 服务器,而不是 MySQL。我认为 MySQL Connector/NET 是您要找的。
我正在尝试使用 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)
SqlClient 用于连接到 Microsoft SQL 服务器,而不是 MySQL。我认为 MySQL Connector/NET 是您要找的。