Question : SQL Database mail error

I have 20+ SP's that:
(1) build and send via dbMail an HTML email ('Subject' and 'Body')
(2) write to the 'DashboardMessage' table various elements of the SP (including the 'Subject' and 'Body' of the email).  
(I have attached an example SP in a code snippet)

Starting yesterday I began getting error messages on all my SP's as follows... <<At least one of the following parameters must be specified. "@body, @query, @file_attachments, @subject". >>  
(see attached pic for messages from App and when I run from EXEC)

What is interesting is that the EXEC error message says 'Line 242'... not sure where it is getting this from? My SP is around 185 rows (see SP Code).

Any thoughts?

Brad



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
USE [audit]
GO
/****** Object:  StoredProcedure [dbo].[mB102IMSOILeaderReAssignment]    Script Date: 07/27/2010 08:41:58 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER procedure [dbo].[mB102IMSOILeaderReAssignment] 
	@profile varchar(max),
	@SourceEmail varchar(max),				--oldC1EM (CC) 
	@ReportID int,
	@RecID int,
	@SourceUserID int,						-- oldC1        
	@OriginatorUserID int,					-- A1ID  
	@TargetUserID int,						-- oldC1IM         
	@Host varchar(max),
	@NotificationName varchar(max)
as

declare @TargetName varchar(max)
set @TargetName = (select u.FirstName + ' ' + u.LastName from Users u
				 where u.ID = @TargetUserID)
				 
declare @TargetTitle varchar(max)
set @TargetTitle = (SELECT     u.TitleDesc
					FROM         Users AS u 
					Where u.ID = @TargetUserID)   		 
				 
declare @SourceName varchar(max)
set @SourceName = (select u.FirstName + ' ' + u.LastName from Users u
				 where u.ID = @SourceUserID)				 

declare @SourceTitle varchar(max)
set @SourceTitle = (SELECT     u.TitleDesc
					FROM         Users AS u 
					Where u.ID = @SourceUserID)	
					
declare @ReportDate varchar(max)
set @ReportDate = (SELECT     convert(char(10), ReportDate, 101) 
					FROM         Reports AS r
					WHERE     r.ID = @ReportID) 
					
declare @AuditExamination varchar(max)
set @AuditExamination = (SELECT       case vcg.ID     when 2 then 'Consultant'
                                                        when 3 then 'Audit'
                                                        when 6 then 'Internal'
                                                        when 9 then 'Examination'
                                                        else '' end
						FROM         VendorCategories AS vc INNER JOIN
									VendorCategoryGroups AS vcg ON vc.VendorCategoryGroupID = vcg.ID INNER JOIN
									Vendors AS v ON vc.ID = v.VendorCategoryID INNER JOIN
									Reports AS r ON v.ID = r.SourceVendorID
						WHERE     (r.ID = @ReportID) )
						
						
						
declare @AuditAreaList varchar(max)
set @AuditAreaList =	(SELECT     dbo.GetAuditAreasForReport(r.ID) AS AuditAreas
						FROM         dbo.Reports AS r INNER JOIN
								dbo.Vendors AS v ON v.ID = r.SourceVendorID LEFT OUTER JOIN
								dbo.ReportsStatus2Distinct ON r.ID = dbo.ReportsStatus2Distinct.ID
						WHERE r.ID = @ReportID)
						

declare @RecommendationLanguage varchar(max)
set @RecommendationLanguage =	(SELECT     r.Observation
								FROM         Recommendations r 
								WHERE r.ID = @RecID)

declare @SupInfoSource varchar(max)
set @SupInfoSource =	(SELECT      
                      (CASE WHEN rec.SupportingInformationSourceReportID IS NOT NULL THEN 'Vendor - ' + (v.Name) WHEN rec.SupportingInformationSourceUserID IS NOT NULL THEN 'User - ' + (u.FirstName + ' ' + u.LastName) WHEN rec.SourceOther IS NOT NULL THEN 'Source - ' + rec.SourceOther ELSE 'Source Not Assigned' END) AS Final                     
						FROM         Recommendations AS rec INNER JOIN
                      Reports AS r ON rec.ReportID = r.ID INNER JOIN
                      Vendors AS v ON r.SourceVendorID = v.ID LEFT OUTER JOIN
                      Users AS u ON rec.SupportingInformationSourceUserID = u.ID
						WHERE rec.ID = @RecID)      						

declare @SupportingInfo varchar(max)
set @SupportingInfo =	(SELECT     r.SupportingInformation
								FROM         Recommendations r 
								WHERE r.ID = @RecID)						

declare @RecRiskLevel varchar(2)
set @RecRiskLevel =	(SELECT     r.RiskLevel
								FROM         Recommendations r 
								WHERE r.ID = @RecID)
								
declare @VendorName varchar(max)
set @VendorName =	(SELECT     v.Name
						FROM         Reports r INNER JOIN
                      Vendors v ON r.SourceVendorID = v.ID 
								WHERE r.ID = @ReportID)														
								
declare @RecNum varchar(2)
set @RecNum =	(SELECT     r.RecommendationNumber
								FROM         Recommendations r 
								WHERE r.ID = @RecID)	
								
declare @SourceNameDate varchar(max)
set @SourceNameDate =	(SELECT     (v.Name + ' - ' + (convert(char(10), r.ReportDate, 101))) 
						FROM         dbo.Reports AS r INNER JOIN
                      dbo.Vendors AS v ON v.ID = r.SourceVendorID LEFT OUTER JOIN
                      dbo.ReportsStatus2Distinct ON r.ID = dbo.ReportsStatus2Distinct.ID
						WHERE r.ID = @ReportID)   
						
declare @FormalResponse varchar(max)
set @FormalResponse = (SELECT     ResponseFormal
						FROM         RecommendationResponders AS rr
						Where RecommendationID = @RecID)						 	
						
declare @ReAssignComments varchar(max)
set @ReAssignComments = (SELECT     SOIReAssignComments
						FROM         RecommendationResponders AS rr
						Where RecommendationID = @RecID)

declare @NewB1ID int
set @NewB1ID = (SELECT     SOILeaderUserID
						FROM         RecommendationResponders AS rr
						Where RecommendationID = @RecID)

declare @ResponsibleUserName varchar(max)
set @ResponsibleUserName = (select u.FirstName + ' ' + u.LastName from Users u
							where u.ID = @NewB1ID)

declare @ResponsibleUserTitle varchar(max)
set @ResponsibleUserTitle = (SELECT     u.TitleDesc
							FROM         Users AS u 
							Where u.ID = @NewB1ID)

declare @html varchar(max)
SELECT @html=Body FROM NotificationContent WHERE NotificationName=@NotificationName

set @html = replace(@html, '[TargetName]', @TargetName)								-- oldC1IM
set @html = replace(@html, '[SourceName]', @SourceName)								-- oldC1Name
set @html = replace(@html, '[SourceTitle]', @SourceTitle)
set @html = replace(@html, '[ReportDate]', @ReportDate)
set @html = replace(@html, '[AuditExamination]', @AuditExamination)
set @html = replace(@html, '[AuditAreaList]', @AuditAreaList)
set @html = replace(@html, '[RecommendationLanguage]', @RecommendationLanguage)
set @html = replace(@html, '[SupInfoSource]', @SupInfoSource)
set @html = replace(@html, '[SupportingInfo]', @SupportingInfo)
set @html = replace(@html, '[RecRiskLevel]', @RecRiskLevel)
set @html = replace(@html, '[FormalResponse]', @FormalResponse)

set @html = replace(@html, '[VendorName]', @VendorName)
set @html = replace(@html, '[RecNum]', @RecNum)
set @html = replace(@html, '[ReAssignComments]', @ReAssignComments)
set @html = replace(@html, '[ResponsibleUserName]', @ResponsibleUserName)
set @html = replace(@html, '[ResponsibleUserTitle]', @ResponsibleUserTitle) 
 


declare @sub varchar(max)
SELECT @sub=Subject FROM NotificationContent WHERE NotificationName=@NotificationName
set @sub = replace(@sub, '[SourceNameDate]', @SourceNameDate)
set @sub = replace(@sub, '[RecNum]', @RecNum)

declare @to varchar(max)
set @to =	(SELECT     u.Email
			FROM         Users as u
			WHERE u.ID = @TargetUserID)




exec msdb.dbo.sp_send_dbmail 
	@profile_name = @profile,
	@recipients = @to,						-- oldC1IM		
	@copy_recipients = @SourceEmail,		-- oldB1
	@subject = @sub,
	@body = @html,
	@body_format = 'HTML'
	
	
INSERT [dbo].[DashboardMessages](
      [EventAlias], [MessageTypeID], [AppSection], [UserID],
      [DateCreated], [HighPriority], [Completed], [Subject], [Message], [RecommendationID])
Select 
Left(@NotificationName,50),4,'Recommendation',@TargetUserID,GetDate(),
1,1,@sub,@html,@RecID
;
INSERT [dbo].[DashboardMessages](
      [EventAlias], [MessageTypeID], [AppSection], [UserID],
      [DateCreated], [HighPriority], [Completed], [Subject], [Message], [RecommendationID])
Select 
Left(@NotificationName,50),5,'Recommendation',@SourceUserID,GetDate(),
1,1, @sub,@html,@RecID
Attachments:
 
ErrorMessageFromApplication
ErrorMessageFromApplication
 
 
ErrorWhenExecFromSSMS
ErrorWhenExecFromSSMS
 

Answer : SQL Database mail error

The line number refers to the line number inside the mail stored procedure - not your stored procedure....


It does sound like you have a NULL value in there somewhere.

Would suggest you should encapsulate all your set @stuff = (select ... )  in a isnull type test e.g.  set @stuff = isnull( (select ...), '')

Or, if NULL values are meant to be impossible, then you might like to check those tables for NULL values.

Random Solutions  
 
programming4us programming4us