Attachment file \\SERVER\file.csv is invalid. [SQLSTATE 42000] (Error 22051). The step failed

柔情痞子 提交于 2019-12-20 04:59:19

问题


I've got 4 SQL servers: SQL Server 2005, SQL Server 2008, SQL Server 2008 R2 and SQL Server 2012.

In SQL Server 2008 R2; I have created a SQL job that sends me email every Monday with reports from SQL Server 2005, SQL Server 2008 and SQL Server 2008 R2 on databases that are older than 3 months and it works just fine.

But, now that I want to add SQL Server 2012, the job fails with the following error:

Executed as user: NT AUTHORITY\SYSTEM. Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install. [SQLSTATE 01000] (Message 15457) Configuration option 'Database Mail XPs' changed from 1 to 1. Run the RECONFIGURE statement to install. [SQLSTATE 01000] (Message 15457) Attachment file \\ServerName\ShareName\Path\SQL2012_DB.csv is invalid. [SQLSTATE 42000] (Error 22051). The step failed.

If I create the same job on SQL Server 2012 I'm getting that the SQL2008R2_DB.csv is invalid.

Here is the steps from the job on SQL Server 2008 R2:

sp_CONFIGURE 'show advanced', 1
GO

RECONFIGURE
GO

sp_CONFIGURE 'Database Mail XPs', 1
GO

RECONFIGURE
GO

USE msdb
GO

EXEC sp_send_dbmail 
  @profile_name='SQL2008R2',
  @recipients=my.email@mail.com',
  @subject='Old DBs',
  @body='DBs attached in csv',
  @file_attachments='\\ServerName\ShareName\Path\SQL05_DB.csv;\\ServerName\ShareName\Path\SQL2008_DB.csv;\\ServerName\ShareName\Path\SQL2008R2_DB.csv;\\ServerName\ShareName\Path\SQL2008R2_DB.csv'

Is it a permission issue between SQL Server 2008 R2 and SQL Server 2012 that I'm missing or is it something else?


回答1:


Ok, so the problem was that the SQL service account didn't have access to the shared folder. And that's why I got the error "Attachment file \\ServerName\ShareName\Path\SQL2008R2_DB.csv is invalid."

Now it works just fine ;)



来源:https://stackoverflow.com/questions/30478569/attachment-file-server-file-csv-is-invalid-sqlstate-42000-error-22051-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!