I'm trying to put together a program that will update a database every half an hour, I have got the timer and everything working the only bit I'm having trouble with is the actual SQL part itself.
When I run the below block of code within a test console application then it works perfectly and it update the database but when I then try it in the service I have created it just keeps throwing out the following error: System.Data.SqlClient.SqlException(0x80131904): Unclosed quotation mark after the character string ')'.'
But I don't get any error in the console version.
string test = "firstline";
string test2 = "Secondline";
SqlConnection myConnection = new SqlConnection("Data Source=***.***.***.**,1433;Network Library=DBMSSOCN; Initial Catalog = Backups; User ID = BackupsUser; Password = ******; ");
try
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand("INSERT INTO Backups (outcome, reason, company) VALUES ('test',@firstline,@secondline)", myConnection);
myCommand.Parameters.Add(new SqlParameter ("@firstline", test));
myCommand.Parameters.Add(new SqlParameter ("@secondline", test2));
myCommand.ExecuteNonQuery();
myConnection.Close();
WriteErrorLog("Database has been updated");
}
catch (Exception e)
{
WriteErrorLog(e.ToString());
}