我有一个 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
那么,这是什么原因造成的,我该如何预防呢?