My package was perfectly fine for couple of days and today whenever I tried to run it, it transferred few columns from the first file in the folder and failed.
The error that I'm getting is:
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near 's'.
Unclosed quotation mark after the character string
'','C:\Users\svojnovic\Dropbox\test\2016-08-31 Race 3 Scale Sheet.csv')'.
My code in the script task is:
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)(Dts.Connections["DBConn"].AcquireConnection(Dts.Transaction) as SqlConnection);
// Writing Data of File Into Table
int counter = 0;
string line;
// MessageBox.Show(fileName);
System.IO.StreamReader SourceFile = new System.IO.StreamReader(fileName);
while ((line = SourceFile.ReadLine()) != null)
{
if (counter > 0)
{
string query = "Insert into " + TableName + " Values ('";
query += line.Replace(FileDelimiter, "','") + "','" + fileName.Replace(SourceFolderPath,"") + "')";
MessageBox.Show(query.ToString());
SqlCommand myCommand1 = new SqlCommand(query, myADONETConnection);
myCommand1.ExecuteNonQuery();
}
counter++;
}
SourceFile.Close();
// move the file to archive folder after adding datetime to it
File.Move(fileName, ArchiveFolder + "\\" + (fileName.Replace(SourceFolderPath, "")).Replace(FileExtension, "") + "_" + datetime + FileExtension);
Dts.TaskResult = (int)ScriptResults.Success;