try
{
//Create our connection strings
string sSqlConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)) + "\\ClaimFiles.mdf;Integrated Security=True;User Instance=True";
MessageBox.Show(sSqlConnectionString);
//Execute a query to erase any previous data from our destination table
string sClearSQL = "DELETE FROM PA";
SqlConnection SqlConn = new SqlConnection(sSqlConnectionString);
SqlCommand SqlCmd = new SqlCommand(sClearSQL, SqlConn);
SqlConn.Open();
MessageBox.Show(SqlCmd.ExecuteNonQuery().ToString());
SqlConn.Close();
}
catch (SqlException ex)
{
//handle exception
StringBuilder errorMessages = new StringBuilder();
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #: " + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"ErrorNumber: " + ex.Errors[i].Number + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Severity Level: " + ex.Errors[i].Class + "\n" +
"Server:" + ex.Errors[i].Server + "\n");
MessageBox.Show(errorMessages.ToString());
}
}
以上是我在C#中的代碼,我使用的是Microsoft SQL Express。上面的代碼在點擊後激活。當我在Visual Studio中運行代碼時,一切正常。但是,當我的項目的文件夾複製到另一臺計算機(操作系統:Windows XP),並運行.exe文件的程序練練SQLEXCEPTION:提供者:SQL網絡接口,錯誤26 - 錯誤定位服務器/實例指定
在建立與服務器的連接出現了一個錯誤。連接到SQL Server 2005時,此故障可能是由於在默認設置下,SQL Server不允許遠程連接。 (提供者:SQL網絡接口,錯誤26 - 錯誤定位服務器/實例指定)
有人可以幫助我,這將是一個很大的幫助來解決這個問題,因爲程序必須在不同的計算機上運行。順便說程序的目標框架是.NET 3.5
你已確保該服務正在運行?您是否確保SQL Server Express甚至安裝在第二臺計算機上? –
另一臺計算機上沒有SQL Server。 –
是否需要在其他計算機上安裝SQL Server? –