0

I have a .NET project [scenario] in which I:

  1. Downloaded files from WinSCP.com library in .NET
  2. Parsed them, created tokens, inserted them into a SQL-DB using LINQ to SQL.

The problem is during converting it into a service. The downloading part goes fine when I run the service, but when pushing into the DB using the LINQ to SQL, it gives an exception without entering even a single row in the database.

Note: the exception found using EventLog is as under:

Application: ErrLogsService_57_92.exe 
Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: 
System.Data.SqlClient.SqlException Stack: at 
System.Data.Linq.DataContext.SubmitChanges(System.Data.Linq.ConflictMode) at 
ErrLogsService_57_92.ErrLogsCreation.Read_Log_File(System.String, Int32, Int32) at 
ErrLogsService_57_92.ErrLogsCreation.parseFileAndPush(Int32) at 

System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.ThreadHelper.ThreadStart() 

The code inserting the data is:

if (CheckLineErrorNot(Line_Str_Is))
{
    sql_DB_LOGS_aDataContext rowInsert = new sql_DB_LOGS_aDataContext();
    Col1 = Get1_Column_DateTime(Line_Str_Is, 0);
    Col2 = Get2_Column_JavaFileName(Line_Str_Is, 59);
    Col3 = Get3_Column_PortNumber(Line_Str_Is, 90);
    Col4 = Get4_Column_ErrorString(Line_Str_Is, endIndexOf_JavaFile, Line_Str_Is.Length);

    // Request creation to insert Error-Logs
    LogsError insertQry = new LogsError
    {
        DateTime = Col1.ToString(),
        FileName = Col2.ToString(),
        PortNumber = Col3.ToString(),
        ErrorString = Col4.ToString(),
        ID_IP = (int)IP,
        ID_FILE = (int)ID_FILE_IS
    };
    rowInsert.LogsErrors.InsertOnSubmit(insertQry);
    rowInsert.SubmitChanges();
}
else
{
    ;
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Asif Mehmood
  • 964
  • 2
  • 14
  • 35

0 Answers0