SQLTeam.com | Weblogs | Forums

sp_send_dbmail Attachment file is invalid Error 22051


#1

I'm having the following problem. My scenario is as follows:

I have an application server and one database (SQL Server 2012), both servers with Windows Server 2008 R2 Data Center

My routine for sending e-mail (sp_send_dbmail), read the shared folder on the application server to send attached files.

This routine always worked. However, I needed to create an online replication and was displaying an error stating that the name of the remote server was different with the server. To resolve this issue ran the script below:

DECLARE @old_name varchar(128), 
@win_nt_server_name varchar(128), 
@server_name varchar(128)

SELECT @old_name = CONVERT(VARCHAR(128), @@SERVERNAME), 
@win_nt_server_name = CONVERT(VARCHAR(128), Serverproperty('Servername')), 
@server_name = (SELECT TOP (1) name from master.sys.servers)
PRINT 'Local SQL Server name:' + @old_name
PRINT 'WindowsNT Server name:' + @win_nt_server_name
PRINT 'Server name:' + @server_name

/*********************************************************************
2) The business end
*********************************************************************/
exec sp_dropserver @old_name
GO
exec sp_addserver @server_name, local
GO

Actually the server name in master.sys.servers table was different to the server, done that solved the problem of my replication.

After this procedure, the e-mail routine crashed when it has attachments. I've done the tests put to read the local folder and the e-mail is sent, but the path of the shared folder displays the error below:

NT SERVICE\SQLSERVERAGENT. Attachment file \Server\ANEXOS\PROPOSTAS\PR_15_0004_3_95.pdf is invalid. [SQLSTATE 42000] (Error 22051)

Folders are with full permission to the database server and Everyone, have changed the sql server agent service user to run as domain administrator and still not worked. I have this same scenario in the production environment running smoothly, including those machines are clones of the production environment.

Any idea what might be and how to solve?


#2

Looks like it's missing a backslash at the beginning of the path, but maybe that was just a mistake when posting it here.

Can you post the sp_send_dbmail command?

Did you try restarting the service after making the drop/addserver? It should not be needed, but it's worth a try if this is a non-prod server.