2012-10-26 44 views
3

我想連接到MS SQL數據庫。 這裏是我的代碼:請啓用TCP/IP協議。 Unity3D

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。並且Iam仍然收到消息:

NotImplementedException:單聲道不支持名稱管道或共享內存 用於連接到SQL Server。請啓用TCP/IP 協議。 System.Data.SqlClient.SqlConnection + SqlMonitorSocket.DiscoverTcpPort (的Int32設置的時間) System.Data.SqlClient.SqlConnection.DiscoverTcpPortViaSqlMonitor (System.String服務器名,System.String實例名) System.Data.SqlClient.SqlConnection.ParseDataSource( System.String theDataSource,System.Int32 & thePort,System.String & theServerName) System.Data.SqlClient.SqlConnection.Open()ConnectToDB.Start()(在 資產/ ConnectToDB.cs:33)

我錯過了什麼?

+0

這似乎不是一個統一問題。這是Mono和MS SQL之間的問題。您應該重新標記/重新提出您的問題,以便MS SQL專家能夠看到它。 – Calvin

+1

「我允許在我的防火牆規則中使用** UDP **端口1434和mono.exe,並且Iam仍然收到消息:」您是否打開過TCP/IP? –

回答