简体   繁体   English

没有详细信息的SQL Server OLEDB错误

[英]SQL Server OLEDB error with no details

I have a SQL Server Agent job running, which uses a stored procedure to do several operations, then exports some data to an xls spreadsheet and emails that spreadsheet. 我有一个SQL Server代理作业正在运行,该作业使用存储过程执行多项操作,然后将一些数据导出到xls电子表格并通过电子邮件将该电子表格发送出去。 Most of the time it works, but several times a month the job fails with the error: 在大多数情况下,它都能正常工作,但一个月内几次会失败,并显示以下错误:

OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. OLE DB提供程序“ Microsoft.Jet.OLEDB.4.0”报告了一个错误。 The provider did not give any information about the error. 提供程序未提供有关该错误的任何信息。 [SQLSTATE 42000] (Error 7399). [SQLSTATE 42000](错误7399)。 The step failed. 该步骤失败。

Thanks, Microsoft, for the detailed error message. 谢谢Microsoft,提供详细的错误信息。 Anyway, the short term fix is usually to simply re-run the job. 无论如何,短期的解决方法通常是简单地重新运行作业。 Usually this works, but in rarer cases it does not, and I must restart the SQL Server instance. 通常,此方法有效,但在极少数情况下则无效,并且我必须重新启动SQL Server实例。

Here is how my code interacts with OLEDB: 这是我的代码与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

So, what is the cause of this, and how can I prevent it? 那么,这是什么原因,如何预防呢?

When you call OPENROWSET, it load the DLL for OLEDB provider for Excel. 调用OPENROWSET时,它将为Excel的OLEDB提供程序加载DLL。 These operations happens inside the SQL Server Stack memory. 这些操作发生在SQL Server堆栈内存中。 When a lot of call to older DLL (ActiveX/COM) are made, it's not impossible that your stack might get full. 当对旧版DLL(ActiveX / COM)进行大量调用时,堆栈可能已满。 You can resolve this in 2 ways: 您可以通过以下两种方法解决此问题:

1) You make these operations outside a TSQL code. 1)您在TSQL代码之外进行这些操作。 You can use a SSIS package for example but you have to change your code not to use OPENROWSET. 例如,您可以使用SSIS包,但必须更改代码以不使用OPENROWSET。 You can use the DTS Wizard to do most of the job. 您可以使用DTS向导完成大部分工作。 This is my personnal recommandation ! 这是我个人的要求!

2) You can also set SQL Server to have a bigger memory Stack by using the -g command parameter. 2)您还可以使用-g命令参数将SQL Server设置为具有更大的内存堆栈。 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. 我认为默认值为256 MB,您可以将其设置为512 MB。为此,您需要打开SQL Server配置管理器。 Depending on your version, you should have a place to change the "Startup Parameters" 根据您的版本,您应该有一个地方可以更改“启动参数”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM