[英]Please enable TCP/IP protocol. Unity3D
I am trying to connect to MS SQL database. 我正在尝试连接到MS SQL数据库。 Here is my code:
这是我的代码:
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;
}
I copyed most of code from mono-project. 我从单项目中复制了大部分代码。 I allowed UDP port 1434 and mono.exe in my firewall rules.
我在防火墙规则中允许UDP端口1434和mono.exe。 And Iam still getting message:
我仍然得到消息:
NotImplementedException: Mono does not support names pipes or shared memory for connecting to SQL Server.
NotImplementedException:Mono不支持名称管道或共享内存以连接到SQL Server。 Please enable the TCP/IP protocol.
请启用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 () (at Assets/ConnectToDB.cs:33)
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)
What am I missing? 我错过了什么?
如果需要帮助建立TCP / IP套接字,您可以使用流行的第三方解决方案,如SmartFox Server或Photon 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.