« Previous Next »

Thread: Code for using COM object for C# .Net with SQL Output

Last post 10-14-2009 4:55 PM by ATSAO. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 06-08-2009, 4:45 PM

    Code for using COM object for C# .Net with SQL Output

    Here's my code that works. I actually dumped log files from System, Application and Security logs into the database.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    // Log Parser 2.2
    using MSUtil;

    namespace LogParser2 {
        public partial class _Default :System.Web.UI.Page {
            // constants
            const string iCHECKPOINT_FILE_LOCATION = @"c:\checkpoint.lpc"; // iCheckpoint allows incremental parsing

            protected void Page_Load(object sender, EventArgs e) {
                GetSystemEventLogToSql();
            }

            private void GetSystemEventLogToSql() {
                try {
                    // Instantiate the LogQuery object
                    LogQueryClassClass LogQuery = new LogQueryClassClass();

                    // Instantiate the Event Log Input Format object
                    COMEventLogInputContextClassClass EvtInputFormat = new COMEventLogInputContextClassClass();

                    // Set Input Parameters.
                    EvtInputFormat.direction = "BW";

                    // iCheckpoint parses input incrementally. Give it a location.
                    EvtInputFormat.iCheckpoint = @"c:\checkpoint.lpc";

                    // Instantiate the Event Log Output Format object
                    COMSQLOutputContextClassClass EvtOutputFormat = new COMSQLOutputContextClassClass();

                    // Set Output Parameters
                    EvtOutputFormat.driver = "SQL Server";
                    EvtOutputFormat.server = "ServerName";
                    EvtOutputFormat.database = "DatabaseName";
                    EvtOutputFormat.username = "UserName";
                    EvtOutputFormat.password = "Password";

                    // I created the tables and added an ID Column. It needs to be ignored during the insert.
                    EvtOutputFormat.ignoreIdCols = true;

                    // Create the query
                    // tblLogWebSystem is the name of the table I am inserting these records into in my DB
                    string Query = @"SELECT * FROM TO tblLogWebSystem";

                    // Execute the query into SQL
                    LogQuery.ExecuteBatch(Query, EvtInputFormat, EvtOutputFormat);

                    Response.Write("Done");
                }
                catch(System.Runtime.InteropServices.COMException exc) {
                    Response.Write("Unexpected error: " + exc.Message);
                }
            }
        }
    }

  • 07-24-2009, 5:49 AM In reply to

    • sebinroy
    • Not Ranked
    • Joined on 07-24-2009, 9:48 AM
    • Posts 1

    Re: Code for using COM object for C# .Net with SQL Output

    This indeed gave me a pointer to the right direction....

    Thanks

  • 10-14-2009, 4:55 PM In reply to

    • ATSAO
    • Not Ranked
    • Joined on 10-14-2009, 8:50 PM
    • Posts 1

    Re: Code for using COM object for C# .Net with SQL Output

    I have some questions about use COM object: 

    1. can I use a .sql file instead of coded in the program? 

    2. can I pass parameters into .sql file like commend line does?

    Thanks,

     

     

Page 1 of 1 (3 items)
Microsoft Communities