How to catch exception in log parser(MSUtil) though SSIS Package while inserting log file data to table?


I am using LogParser tool (MSUtil dll) to insert data in db through SSIS Package.

I am using following code in script task component:

Looping through log files and using following :

 

 private bool InsertLogParserToSQL()
        {

            LogQueryClass logQuery = new LogQueryClass();

            COMIISW3CInputContextClass inputContext = new COMIISW3CInputContextClass();
            COMSQLOutputContextClass outputContext = new COMSQLOutputContextClass();

            bool result = false;
            string errMessage = string.Empty;

            try
            {
               
                inputContext.consolidateLogs = true;
                inputContext.recurse = 0;

                outputContext.clearTable = false;
                outputContext.createTable = false;
                outputContext.fixColNames = true;
                outputContext.ignoreIdCols = true;
                outputContext.ignoreMinWarns = false;
               
                outputContext.transactionRowCount = -1;


                outputContext.database = DatabaseName;
                outputContext.server = ServerName;
                outputContext.username = UserName;
                outputContext.password = Password;
                outputContext.driver = DriverName;

                DirectoryInfo info = new DirectoryInfo(System.IO.Path.GetDirectoryName(DirectoryName));
                FileInfo[] logFileInfo = info.GetFiles();

                foreach (FileInfo fi in logFileInfo)
                {
                    string logiles = DirectoryName.TrimEnd('\\') + '\\' + fi.Name;
                    String query = "SELECT TO_LOCALTIME(QUANTIZE(TO_TIMESTAMP(date, time), 3600)),time,cs-method,cs-uri-stem,cs-uri-query,cs-username,c-ip,cs(User-Agent),cs(Referer),cs-host,sc-status,sc-substatus,sc-win32-status,time-taken  FROM '" + logiles + "' TO logData";

                    try
                    {
                        logQuery.ExecuteBatch(query, inputContext, outputContext);
                        result = (logQuery.lastError == 0);
                        errMessage = logQuery.errorMessages.ToString();
                    }
                    catch (System.Runtime.InteropServices.COMException exc)
                    {
                        Console.WriteLine("Unexpected error: " + exc.Message);
                        return result;
                    }

                    if (errMessage != null)
                    {
                        Console.WriteLine("Logs added to database.\r\n\r\n");
                  
                    }
                    else
                    {
                        Console.WriteLine("Logs failed to add to database.\r\n\r\n" + logQuery.lastError.ToString() + " at " + logiles);
                       
                    }
                }
                return result;
            }
            catch (System.Runtime.InteropServices.COMException exc)
            {
                Console.WriteLine("Unexpected error: " + exc.Message);
                return result;
            }
            if (result)
            {
                Console.WriteLine("Logs added to database.\r\n\r\n");
            }
            else
            {
                Console.WriteLine("Logs failed to add to database.\r\n\r\n");
            }
            return result;

        }

By this code,only half data is inserted in table and it doesn't throw any exception .

And my another question is : Is there any faster way to process log file(8-10 lacs) data to db through SSIS Package other than script component?

 

Please guide.Thanks.


Asked by:- SnehalSawant
0
: 29 At:- 12/4/2018 11:46:02 AM
c# SSIS

Can you explain little bit more about the results which you are expecting and what is current results? Thanks 0
By : vikas_jk - at :- 12/6/2018 4:24:45 PM







Login/Register to answer
Or
Post answer directly by entering your email-id & Name

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use