3

我有一个创建文本日志文件的应用程序,并且我有一个每日 SQL Server 作业,它截断日志表并使用批量插入来加载当前日期日志。日志文件由许多线程写入,如果不按线程手动整理行,则很难阅读。

有没有办法让 SQL Server 'tail' 给定文件并使表保持最新而无需等待一天结束的批处理?我不想在白天多次运行批处理,因为该表将由 Web 服务监视/搜索/显示。从应用程序直接记录到表中目前也不是一种选择。

4

1 回答 1

1

I would have done it through CLR and the job.

  1. To have a job that runs at a certain intervals.
  2. Create CLR function that accepts file name and current line number in the file.

CLR will open file and based on a give number will fetch data after specified line and return back to sql server.

Line number will be stored in auxiliary table for the future synchronization purposes.

Here is article how to write CLR to return table back to sql server : http://msdn.microsoft.com/en-us/library/ms131103.aspx

Good luck.

于 2012-10-24T16:15:23.693 回答