开发者社区> 问答> 正文

SQL Server与Unity的连接

我正在尝试将Unity项目连接到SQL Server。我已成功在Visual Studio 2017中连接Windows窗体应用程序。而且我认为,如果将确切的代码复制到统一脚本中,我的目标应该会实现。我已将System.Data.Dll V3.5资产导入并使用unity2018.2.1.f1。我正在使用以下脚本尝试首先打开连接。

void Start () 
{
    try
    {
        string ConnString = "Integrated Security=SSPI;" + "Initial Catalog=UnityTest;" + "Data Source=localhost;";
        SqlConnection MyConn = new SqlConnection(ConnString);
        MyConn.Open();
        Debug.Log("Connection opened !");
    }
    catch(System.Exception ex)
    {
        Debug.Log(ex.ToString());
    }
}

出现以下错误: System.Data.SqlClient.SqlException: Server does not exist or connection refused.

Mono.Data.Tds.Protocol.TdsInternalException: Server does not exist or connection refused.

System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used.

at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in :0 at System.Net.Sockets.Socket+Worker.Connect () [0x00000] in :0 --- End of inner exception stack trace --- at Mono.Data.Tds.Protocol.TdsComm..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion) [0x00000] in :0 at Mono.Data.Tds.Protocol.Tds..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion) [0x00000] in :0 at Mono.Data.Tds.Protocol.Tds70..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion version) [0x00000] in :0 at Mono.Data.Tds.Protocol.Tds80..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout) [0x00000] in :0 at Mono.Data.Tds.Protocol.TdsConnectionPoolManager.CreateConnection (Mono.Data.Tds.Protocol.TdsConnectionInfo info) [0x00000] in :0 at Mono.Data.Tds.Protocol.TdsConnectionPool.GetConnection () [0x00000] in :0 at System.Data.SqlClient.SqlConnection.Open () [0x00000] in :0 --- End of inner exception stack trace --- at System.Data.SqlClient.SqlConnection.Open () [0x00000] in :0 at DB.Start () [0x00010] in D:\UnityProjects2018\DataBaseTest1\Assets\DB.cs:15 UnityEngine.Debug:Log(Object) DB:Start() (at Assets/DB.cs:20)

展开
收起
心有灵_夕 2019-11-30 21:21:23 1055 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
SQL Server在电子商务中的应用与实践 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载