0

Through a windows service, I'm trying to insert the sc-bytes and the cs-bytes into a sql server. I'm able to do this via the command prompt windows but when I'm trying to add this in my windows service, it acts dead. I already tested the connection and the LogParser 2.2 commands.

What am I missing / doing wrong?

my code:

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.UseShellExecute = false;
    startInfo.FileName = @"cmd.exe";
    startInfo.Arguments = @"""C:\Program Files (x86)\Log Parser 2.2\Logparser.exe""" + " \"SELECT date, 4, DIV(DIV(SUM(cs-bytes), 1024), 1024) AS [MBytes received], DIV(DIV(SUM(sc-bytes), 1024), 1024) AS [MBytes sent], COUNT(*) AS Requests INTO tblHostingStatistics FROM <devcom2.be> GROUP BY date ORDER BY date DESC\" -server:mysqlserver -database:database -username:user -password:pass -o:SQL";
    process.StartInfo = startInfo;
    process.Start();

Any help would be much appreciated

Dieter B
  • 1,142
  • 11
  • 20

1 Answers1

0

There are tons of issues with starting command-line tools from within the IIS worker process. For one, you need to make sure the worker process identity has privileges to execute LogParser.exe (and also cmd.exe in your example, which is however redundant).

You'd be better off with using the LogParser COM objects, which were designed exactly for these scenarios.

Gabriele Giuseppini
  • 1,541
  • 11
  • 19