原文地址http://www.cnblogs.com/fish-li/p/3139366.html

使用Log Parser将IIS日志导入SQL Server

"C:\Program Files\Log Parser 2.2\logparser.exe"  

"SELECT  *  FROM  'D:\Temp\u_ex130615.log'  to tbname" -i:IISW3C -o:SQL

-oConnString:"Driver={SQL Server};server=localhost\sqlexpress;database=dbname;uid=sa;pwd=123456;" 

-createtable:ON

注意:

1.IIS日志在将结果导出到SQLSERVER时,字段名中不符合标识符规范的字符将会删除。

   例如:c-ip 会变成 cip, s-port 会变成 sport 。

2.IIS日志中记录的时间是UTC时间,而且把日期和时间分开了,导出到SQLSERVER时,会生成二个字段date和time:

   1.在SQLSERVER中增加一列,然后把UTC时间换成本地时区的时间,T-SQL脚本如下:

 alter table tbname add RequestTime datetime

    go

    update tbname set RequestTime=dateadd(hh,8,convert(varchar(10),date,120)

           + ' ' + convert(varchar(13),time,114))

   2.直接在导出IIS日志时,把时间转换过来,此时要修改命令:

     "C:\Program Files\Log Parser 2.2\logparser.exe"  

     "SELECT TO_LOCALTIME(TO_TIMESTAMP(ADD(TO_STRING(date, 'yyyy-MM-dd '), TO_STRING(time,                   'hh:mm:ss')),'yyyy-MM-dd hh:mm:ss')) AS RequestTime, *  FROM  'D:\Temp\u_ex130615.log'  to  tbname" 

      -i:IISW3C -o:SQL

      -oConnString:"Driver={SQL Server};server=localhost\sqlexpress;database=tbname;uid=;pwd=;"

      -createtable:ON


查询访问量最大的IP

select cip,count(*) from tbname group by cip order by count(*) desc