Troubleshooting Error Code 0×80004005
Written by Mike Rede on July 9, 2009There are several situations where you may encounter error code 0×80004005.
You can receive the error code 0×80004005 if you use Distributed Authoring and Versioning (DAV) to query for message properties on the information store in Microsoft Exchange 2000 Server or Microsoft Exchange Server 2003. A 0×80004005 (ecCallFailed) error is returned if the urn:schemas:mailheader:to property is requested. Additionally, an error is returned if there are messages in the result set that have recipients where the value of PR_EMAIL_ADDRESS is an empty string (”").
You may also receive the error when you use xp_sendmail extended stored procedure to send e-mail from SQL Mail with SQL Server 2000. The error message you receive will look like: xp_sendmail:failedwithmailerror 0×80004005.
Another circumstance when you receive error code 0×80004005 is when you query for a specific MAPI interface by using a pointer that you obtained from an Outlook object’s MAPIOBJECT property. The error message is short: 0×80004005 (E_FAIL).
When this happens it is because The MAPIOBJECT property is available only for compatibility with Microsoft Collaboration Data Objects (CDO) 1.21. It is a hidden property of Outlook Object Model objects, and is not meant to be used from the Outlook object. The MAPIOBJECT property is meant to be used from the corresponding CDO object. To use the MAPIOBJECT property, use CDO to obtain it from the corresponding CDO object.
Additionally, a SQL Server Database Maintenance Plan includes an option to send a maintenance report (that is, a file that contains results for the execution of the maintenance plan) by e-mail to a predefined operator on the server. E-mailing the maintenance report file to the operator may fail with the following error message, which can be found in the maintenance report for the Database Maintenance Plan:
Error 18025: [Microsoft][ODBC SQL Server Driver][SQL Server]xp_sendmail: failed with mail error 0×80004005.
Note that this error does not affect the reporting of the job status. The job is still shown as successful.
The xp_sendmail extended stored procedure fails with the 0×80004005 error when attempting to send an open file as an e-mail attachment. Sqlmaint.exe executes the Maintenance Plan and writes output to the report file. The final step in the Maintenance Plan, which is to send an e-mail, is also recorded in the report. Because the report file is still open when xp_sendmail tries to send it as an attachment, the attempt fails.
You can resolve this problem by obtaining the latest service pack for SQL Server 2000.
Microsoft has confirmed that this is a problem in SQL Server 2000. This problem was first corrected in SQL Server 2000 Service Pack 1.
To work around this problem, you can include the script below as an additional job step in the last job created by a particular Maintenance Plan. This script below sends the last report file for a specific Maintenance Plan to a specified e-mail address.
To use this workaround, follow these steps:
- Identify the last job for the Maintenance Plan.
- Right-click the job, click Properties, click Steps, select the step, and then click Edit.
- On the Edit Job Step dialog box, click the Advanced tab.
- Set On Success Action to Go To Next Step.
- Click OK on the Edit Job Step dialog box.
- Click New to add a new step, and then give the step a name. Type should be Transact-SQL Script (TSQL) and Database should be master.
- Paste the following script in the command window:
declare @planname varchar(100)
declare @dir varchar(200)
declare @operator varchar(50)
declare @cmd varchar (200)
declare @mailfilename varchar(200)
declare @filenamelen int
Values set here can actually be provided as parameters to a stored procedure.
If provided as parameters to a stored procedure, rem the following select statements.
@plananme is the plan whose maintenance report is sent.
@dir is the log directory for SQL Server. It is the directory to which the maintenance report files are written.
@operator is the email address of the person to whom the report file should be mailed.
select @planname = ‘Database Maintenance Plan 1′
select @dir =’c:Program FilesMicrosoft SQL ServerMSSQL$SQL2K1LOG’
select @operator =’email@domain.com’
You can automatically set the above by reading various values from SQL Server.
SET NOCOUNT ON
IF RIGHT (@dir, 1) <> ‘’
begin
select @dir =@dir +’’
end
SELECT @dir = ‘dir /s /b ‘+’”‘+@dir + @planname+’*.txt’+'”‘ +’ >c:dir.txt’
create table #TMP_MAINT_FILENAMES (NAME1 varchar(8000))
exec xp_cmdshell @dir
BULK INSERT #TMP_MAINT_FILENAMES
FROM ‘c:dir.txt’
WITH
(
ROWTERMINATOR = ‘n’
)
select @mailfilename=MAX(name1) from #TMP_MAINT_FILENAMES
print ‘The following file is being sent as an attachment’
print @mailfilename
Set the various parameters for xp_sendmail.
declare @tmpmessage varchar(300)
declare @tmpsubject varchar(300)
select @tmpmessage = ‘This is the last maintenance report on the server for the maintenance plan ‘+@planname
select @tmpsubject = ‘SQL Server Maintenance Report for ‘+@planname
Now send the last file for the maintenance plan.
exec master..xp_sendmail @recipients= @operator, @subject =@tmpsubject, @message=@tmpmessage,
@attachments= @mailfilename
Perform cleanup.
drop table #TMP_MAINT_FILENAMES
exec master..xp_cmdshell “del c:dir.txt”
SET NOCOUNT OFF
8. Make sure that the @planname, @dir, and @operator values are set in the script.
9. Save the job step.
These programming examples are provided for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. Make sure that you are familiar with the programming language that is shown and with the tools that are used to create and to debug procedures.


