Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

A severe error occurred on the current command Expand / Collapse
Author
Message
Posted Thursday, June 26, 2008 10:54 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, June 28, 2008 1:01 AM
Points: 1, Visits: 3
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


Post #524759
Posted Monday, June 30, 2008 3:57 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:56 AM
Points: 7,010, Visits: 8,462
So you see you would be better off using dbmail !
(better in sql2005 and nomore need for oa-stuff !!)



Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- 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
Post #525782
Posted Tuesday, September 24, 2013 12:41 PM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, September 13, 2014 8:22 PM
Points: 47, Visits: 139
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
Post #1498014
Posted Wednesday, September 25, 2013 7:06 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:10 PM
Points: 11,322, Visits: 13,115
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

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

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
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #1498329
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse