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());
}
}
Above is my code in C#, i'm using Microsoft SQL express. the code above is activated upon a click. When i run the code in Visual Studio everything works fine. But when i copy the folder of the project to a different computer(OS: Windows XP) and run the .exe file the program catches a SqlException:
An error has occured while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error 26 - Error Locating Server/Instance Specified)
Can someone help me with this, it would be a great help to solve this problem, because the program must run in a different computer. By the way program's target framework is .NET 3.5