我正在使用Visual C#Express 2008,並通過轉到Add-> New Data Source來創建數據庫和數據集。我試圖向它添加一條記錄,但無法使用嚮導中提供的數據字符串進行連接。請幫忙。這是我的代碼C#.NET連接字符串無法連接
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("Data Source=|DataDirectory|\\myLife.sdf;Password=*******");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT profiles (profile, file) VALUES ('here', 'here')";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
什麼是錯誤?數據庫文件是否存在?它在正確的位置嗎?它是否可由適用的用戶環境寫入? – David 2010-10-13 18:51:58
你得到什麼錯誤? – CodingGorilla 2010-10-13 18:52:30
與SQL Server建立連接時發生網絡相關或特定於實例的錯誤。服務器未找到或無法訪問。驗證實例名稱是否正確,並將SQL Server配置爲允許遠程連接。 (提供程序:命名管道提供程序,錯誤:40 - 無法打開連接到SQL Server) – 2010-10-13 18:59:50