1

我有一个 SQL Server 代理作业正在运行,它使用存储过程执行多项操作,然后将一些数据导出到 xls 电子表格并通过电子邮件发送该电子表格。大多数情况下它都可以工作,但每月有几次作业失败并出现错误:

OLE DB 提供程序“Microsoft.Jet.OLEDB.4.0”报告错误。提供商没有提供有关该错误的任何信息。[SQLSTATE 42000](错误 7399)。步骤失败。

感谢 Microsoft,提供详细的错误消息。无论如何,短期修复通常是简单地重新运行工作。通常这可以工作,但在极少数情况下不会,我必须重新启动 SQL Server 实例。

以下是我的代码与 OLEDB 交互的方式:

    Insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 5.0;Database=\\Excel\POStatus\POStatus.xls;', 
   'SELECT * FROM [POStatus$]')  

Select --Tons of columns with tons of math and functions
FROM --5 tables joined together (left joins)
WHERE -- Tons of where conditions
Order by --Case statement for custom sorting

Set @vCommand =  'copy \\Excel\POStatus\POStatus.xls \\Excel\POStatus\POStatus_' + @vDate + '.xls'

EXEC master..xp_cmdshell @vCommand , NO_OUTPUT

... omitted for brevity...

  Set @nvSubject = ' POStatus ' + @vDate
  Set @nvMessage = ' This is an automated message, please respond to the IS department,  thank you ' 
  Set @nvMessage = @nvMessage + char(13) + char(10)

      Set @nvAttachments = '\\Excel\POStatus\POStatus_' + @vDate + '.xls'

      Exec master..xp_sendmail 
           @recipients = @nvRecipients , @copy_recipients = @nvCopy_recipients ,
           @subject = @nvSubject , @message = @nvMessage ,  
           @query = @nvQuery , @width = @iWidth , @attachments = @nvAttachments

那么,这是什么原因造成的,我该如何预防呢?

4

1 回答 1

0

When you call OPENROWSET, it load the DLL for OLEDB provider for Excel. These operations happens inside the SQL Server Stack memory. When a lot of call to older DLL (ActiveX/COM) are made, it's not impossible that your stack might get full. You can resolve this in 2 ways:

1) You make these operations outside a TSQL code. You can use a SSIS package for example but you have to change your code not to use OPENROWSET. You can use the DTS Wizard to do most of the job. This is my personnal recommandation !

2) You can also set SQL Server to have a bigger memory Stack by using the -g command parameter. I think 256 MB is the default and you can set it to 512. To do that you need to open the SQL Server Configuration Manager. Depending on your version, you should have a place to change the "Startup Parameters"

于 2012-10-09T01:52:03.880 回答