Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Send db mail task fails in SSIS Package with error

Author  Topic 

Maina
Starting Member

1 Post

Posted - 2013-03-11 : 23:51:39
0 down vote favorite


I am trying to execute this sql task in SSIS package which send an email when the file name is not found. I have declared this user-defined variable "@PackageStartTime" in my ssis package. But when my SSIS package hit this task it fails with following error.

"Executing query DECLARE @PackageStartTime Varchar(250) SET @Packag...." failed with the error.: "Parameter name is unrecognized." Possible failure reasons: Problem with the query, "ResultSet" Property not set correctly, parameters not set correctly, or connection not established correctly."

DECLARE @PackageStartTime Varchar(250)
SET @PackageStartTime =?

IF(SELECT COUNT(*)
FROM [dbo].[Table1] WHERE RowCDate >=@PackageStartTime)>0

BEGIN

DECLARE @SUB Varchar(250)
SET @SUB = 'File Failed'+@@SERVERNAME

DECLARE @BODY Varchar(250)
SET @BODY = 'File Failed'+@@SERVERNAME

EXEC msdb.dbo.sp_send_dbmail @profile_name='default',
@recipients='dev@null.com',
@subject=@SUB,
@body=@BODY,
@query= 'SELECT DISTINCT FileLoadName
FROM [dbo].[Table1] WHERE RowCDate >=@PackageStartTime',
@attach_query_result_as_file=1

I am unable to understand. I have just added a variable User::strPackageStartTime as Datatype = String and Value is blank. I don't have that variable in parameter mapping in Execute SQL Task Editor. Is there I am missing something?

Thank in advance. I am sorry. I am new to this website

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-12 : 00:26:59
the easiest way to do this is to create a variable for query (say User::strSQLQuery. Then make evaluate as expression true for it and set expression as

"IF(SELECT COUNT(*)
FROM [dbo].[Table1] WHERE RowCDate >=@PackageStartTime)>0
BEGIN
DECLARE @SUB Varchar(250)
SET @SUB = 'File Failed'+@@SERVERNAME

DECLARE @BODY Varchar(250)
SET @BODY = 'File Failed'+@@SERVERNAME

EXEC msdb.dbo.sp_send_dbmail @profile_name='default',
@recipients='dev@null.com',
@subject=@SUB,
@body=@BODY,
@query= 'SELECT DISTINCT FileLoadName
FROM [dbo].[Table1] WHERE RowCDate >= " + @[User::strPackageStartTime] + " ',@attach_query_result_as_file=1"

then use this variable inside sql task after making SQLSourceType as variable. You dont need to do any mapping in parameters tab for this

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-12 : 00:30:15
Hi,

Check this link.. It may help you
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=157894
http://www.sqlis.com/sqlis/post/The-Execute-SQL-Task.aspx

--
Chandu
Go to Top of Page
   

- Advertisement -