Reputation: 197
(Sql Server 2014, Windows Server) Running into a frustrating issue running a Database Mail stored procedure including an attachment on a local shared server.
EXEC msdb.dbo.sp_send_dbmail
...
,@file_attachments = '\\localServer\subfolder\file.txt
Unfortunately the error is arising on executing this:
Attachment file \\localServer\subfolder\file.txt is invalid.
Searching online, it looks as though a common cause of this is that the SQL service account (Or server agent? This was unclear) does not have permission to the file system specified. However, this shouldn't be the case here. The domain account assigned to the SQL service account(s) can view and modify all files that are trying to be attached.
Through SQL configuration manager both the SQL Server and SQL Server Agent services have been supplied with a domain administrator user account which has access to this server. However the issue is still occuring. These services have been restarted.
One further complication is that launching with another attachment from the same server, e.g:
EXEC msdb.dbo.sp_send_dbmail
...
,@file_attachments = '\\localServer\another_subfolder\file.txt
Works exactly as expected, and the mail with attached file is sent successfully. The permissions on this folder/file are identical to the permissions on the folder/file which fails on attachment.
What could be causing this, are any further changes to the SQL services required?
Upvotes: 0
Views: 3173
Reputation: 135
I'd add a comment but don't have the reputation :).
I ran into some issues when file names would have invalid characters in them (different encodings/character pages). try to rename the 'file to be sent' to a new simple name and retry sending it, to ensure it's not caused by this. In my case (~~10 years ago), the file name seemed ok when viewing it from windows explorer but the mail client did not accept the name.
Also, you could use mklink to create a local folder pointing to that share. In this way you eliminate the UNC pathing issue from the problem.
Upvotes: 2