我正在尝试将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)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。