我創建使用VS2008
的WIndows CE 6.0
設備與.Net Compact Framework 3.5
無效的連接
這裏一個智能設備項目是我的代碼:
string queryString = "SELECT id, name, insert_date, activity FROM dbo.[my Table]";
StringBuilder errorMessages = new StringBuilder();
using (SqlConnection connection = new SqlConnection("Data Source=dba;Initial Catalog=myDb;Persist Security Info=True;User ID=usern;Password=paswd"))
{
SqlCommand command = new SqlCommand(queryString, connection);
try
{
connection.Open();
//command.Connection.Open();
//command.ExecuteNonQuery();
}
catch (SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
Debug.WriteLine(errorMessages.ToString());
}
}
記住使用者名稱蟻表名稱被更改但我收到以下錯誤command.Connection.Open();
Index #0
Message: Invalid connection.
LineNumber: 0
Source: .Net SqlClient Data Provider
Procedure: ConnectionOpen (Invalid Instance()).
爲什麼以及如何解決它?如果有用的話,該設備很容易對服務器進行配置。
任何人都有同樣的問題? – HellOfACode