June 26, 2008 at 10:54 pm
When iam Running the Stored procedure there is an error occuring
"A severe error occurred on the current command"
this is my code..
this is using for sending mail to clients
if iam sending mail without attachment its working perfectly
but if i attach a file then that error occured...
please help me
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[SSL_SEND_EMAIL]
@From as nvarchar(50),
@To as nvarchar(2000),
@cc as varchar(2000),
@Subject as nvarchar(255),
@Body as text,
@Attachment as varchar(1000)
)
AS
-- Declare
SET NOCOUNT ON;
DECLARE @server varchar(30)
SET @server= (select Mast_Text from MasterSettings where Mast_Id=2)
DECLARE @message int
DECLARE @config int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
EXEC @hr = sp_OACreate 'CDO.Message', @message OUT -- create the message object
EXEC @hr = sp_OACreate 'CDO.Configuration', @config OUT -- create the configuration object
-- Configuration Object
EXEC @hr = sp_OASetProperty @config, 'Fields(cdoSendUsingMethod)', 'cdoSendUsingPort'
EXEC @hr = sp_OASetProperty @config, 'Fields(cdoSMTPServer)', @server
EXEC @hr = sp_OASetProperty @config, 'Fields(cdoSMTPServerPort)', 25
EXEC @hr = sp_OASetProperty @config, 'Fields(cdoSMTPAuthenticate)', 'cdoAnonymous'
EXEC sp_OAMethod @config, 'Fields.Update'
-- Message Object
EXEC @hr = sp_OASetProperty @message, 'Configuration', @config
EXEC @hr = sp_OASetProperty @message, 'To', @To
EXEC @hr = sp_OASetProperty @message, 'Cc', @cc
EXEC @hr = sp_OASetProperty @message, 'From', @From
EXEC @hr = sp_OASetProperty @message, 'Subject', @Subject
EXEC @hr = sp_OASetProperty @message, 'HTMLBody', @Body
if(isnull(@Attachment,'')<>'')
Begin
--EXEC @hr = sp_OAMethod @message, 'AddAttachment', NULL, @Attachment
End
EXEC @hr = sp_OAMethod @message, 'Send', NULL
---- Destroys the objects
EXEC @hr = sp_OADestroy @message
EXEC @hr = sp_OADestroy @config
-- Errorhandler
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @message, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
SET NOCOUNT OFF;
END
if iam comment following part its work perfectly
if(isnull(@Attachment,'')<>'')
Begin
--EXEC @hr = sp_OAMethod @message, 'AddAttachment', NULL, @Attachment
End
************************************************
Note:--this attachment already created in the link server and iam fetching that file from there
when iam creating a file its work perfectly
but when iam fetching that file and send that error occuring
June 30, 2008 at 3:57 am
So you see you would be better off using dbmail !
(better in sql2005 and nomore need for oa-stuff !!)
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
September 24, 2013 at 12:41 pm
A major problem with dbmail is that you cannot specify the From address at run time; you have to set up a different profile for every From address you want to use.
Sincerely,
Daniel
September 25, 2013 at 7:06 am
JediSQL (9/24/2013)
A major problem with dbmail is that you cannot specify the From address at run time; you have to set up a different profile for every From address you want to use.
Since this is a 2005 forum I'll assume that this is actually a 2005 server we are talking about so you are correct, @from_address was added as a parameter to sp_send_dbmail in 2008.
Still I would consider this an annoyance, not a major problem since there is a workaround. Especially in comparison to the sever error that is being caused by using sp_OA* in this case. So I would still recommend using sp_send_dbmail over sp_OA*
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply