gpt4 book ai didi

c# - 系统.Data.SqlClient.SqlConnection “Exception: Unknown packet type 74”

转载 作者:行者123 更新时间:2023-11-29 00:02:46 26 4
gpt4 key购买 nike

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

--- 主.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 Server,而不是 MySQL。我想MySQL Connector/NET是您正在寻找的。

关于c# - 系统.Data.SqlClient.SqlConnection “Exception: Unknown packet type 74”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28996133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com