This works:
EXEC msdb..sp_send_dbmail
@recipients = 'myaddress@helloworld.co.uk',
@subject = 'HELLO WORLD',
@Importance = 'LOW',
@body = 'HELLO WORLD',
@file_attachments = N'UNCpathway\experimental attachment.txt'
Whereas when I try this
EXEC msdb..sp_send_dbmail
@recipients = 'myaddress@helloworld.co.uk',
@subject = 'HELLO WORLD',
@Importance = 'LOW',
@body = 'HELLO WORLD',
@file_attachments = N'UNCpathway\experimental attachment.xlsx'
I get the following error message:
Msg 22051, Level 16, State 1, Line 0 Failed to open attachment file
‘UNCpathway\experimental attachment.xlsx’.
Executing API ‘CreateFile’ failed with error number 32.
The message is strange as I’m not asking for the attachment to be opened!
Why?
How do I allow these attachments to be used?
“Opened” means “accessed by the mailer so that the bytes stored in the file can be copied into the email,” not presenting the file to the user.
CreateFileis often used for opening files for this kind of access.Error code 32 is
ERROR_SHARING_VIOLATION.So the mailer cannot read the attachment file because something else is reading it.