我正在尝试连接到 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;
}
我从 mono-project 复制了大部分代码。我在防火墙规则中允许了 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)
我错过了什么?