[英]Please enable TCP/IP protocol. Unity3D
我正在嘗試連接到MS SQL數據庫。 這是我的代碼:
void Start ()
{
string connectionString =
"Server=MyServer;" +
"Database=Data;" +
"User ID=User;" +
"Password=psd;" +
"Integrated Security=SSPI";
Debug.Log("conn string");
List<int> result = new List<int>();
string sql = "SELECT RecordCount FROM MainDB";
IDbConnection dbcon;
dbcon = new SqlConnection (connectionString);
dbcon.Open ();
IDbCommand dbcmd = dbcon.CreateCommand ();
dbcmd.CommandText = sql;
IDataReader rdr = dbcmd.ExecuteReader ();
while (rdr.Read()) {
result.Add ((int)rdr.GetValue(0));
}
Debug.Log("get");
// clean up
rdr.Close ();
rdr = null;
dbcmd.Dispose ();
dbcmd = null;
dbcon.Close ();
dbcon = null;
}
我從單項目中復制了大部分代碼。 我在防火牆規則中允許UDP端口1434和mono.exe。 我仍然得到消息:
NotImplementedException:Mono不支持名稱管道或共享內存以連接到SQL Server。 請啟用TCP / IP協議。 System.Data.SqlClient.SqlConnection + SqlMonitorSocket.DiscoverTcpPort(Int32 timeoutSeconds)System.Data.SqlClient.SqlConnection.DiscoverTcpPortViaSqlMonitor(System.String ServerName,System.String InstanceName)System.Data.SqlClient.SqlConnection.ParseDataSource(System.String theDataSource, System.Int32&thePort,System.String&theServerName)System.Data.SqlClient.SqlConnection.Open()ConnectToDB.Start()(在Assets / ConnectToDB.cs:33)
我錯過了什么?
如果需要幫助建立TCP / IP套接字,您可以使用流行的第三方解決方案,如SmartFox Server或Photon 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.