Sql Server Database Mail attachments from FileTable msg 22015 (file is invalid)

4k views Asked by At

I'm transitioning email services in an web (mvc3) application from .Net to sql Database Mail. Some of the content we want to send as attachments has been uploaded to a sql FileTable. When I use the UNC path for the attachment (@file_attachments=), I get this error:

Msg 22051, Level 16, State 1, Line 0 Attachment file
\\computername\mssqlserver\foldername\foldername\DE107D2C-B945-4F1E-A4B9-4B398C9DE758.jpg)
is invalid.

I can open the file directly using the same path, and when I copy the file to a local folder, the file attaches fine. I suspect that the issue is folder permission for the FileTable directory. But I can't find any hooks to set the rights for that folder.

I'm running the EXECUTE msdb.dbo.sp_send_dbmail locally in SSMS (local sql instance) using windows authentication.

Any suggestions would be much appreciated.

2

There are 2 answers

0
Reuven Trabin On

This behavior was validated in the Microsoft Database Engine forum and I submitted feedback: https://connect.microsoft.com/SQLServer/feedback/details/756716/sql-server-database-mail-attachments-from-filetable-msg-22051-file-is-invalid

Note that the error code I had in this title should be 22051 and not 22015.

In the mean time, I'm using a work around of copying the files using the sql command shell to another local folder, and using that path for the attachment

Thanks.

0
Praveen Kumar On

share your attachement folder to Network service user in which attchment file exist. and give attachemnt file path like \\ip_addres\filefolder\abc.pdf to send_dbmail stored procedure. This will work if file and sql server are on different machines