05 February 2008 05:23
tonyrogerson
Little note to self; CLR - Passing more than 4000 characters to a CLR stored procedure/udf (varchar(max))
An update to my SMTP Email VB.NET CLR stored procedure, realised it only accepts 4000 bytes max, to fix this use SqlFacet eg...
<SqlFacet(MaxSize:=-1)> ByVal Body As SqlString
Example usage....
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.Runtime.InteropServices
Imports System.Net.Mail
Partial Public Class StoredProcedures
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Function SMTPFullEmail(ByVal SMTPServer As SqlString, _
ByVal SenderEmail As SqlString, _
ByVal FromEmail As SqlString, _
ByVal FromName As SqlString, _
ByVal ToEmail As SqlString, _
ByVal ReplyTo As SqlString, _
ByVal Subject As SqlString, _
<SqlFacet(MaxSize:=-1)> ByVal Body As SqlString, _
ByVal AttachmentFileName As SqlString, _
<Out()> ByRef SendStatus As SqlString) As SqlInt32
Dim Message As New MailMessage
' Set up the message
Message.Sender = New MailAddress(SenderEmail.ToString)
Message.From = New MailAddress(FromEmail.ToString, FromName.ToString)
Message.To.Add(ToEmail.ToString)
Message.Subject = Subject.ToString
Message.Body = Body.ToString
Message.IsBodyHtml = True
If AttachmentFileName.ToString <> "" Then Message.Attachments.Add(New Attachment(AttachmentFileName.ToString))
Dim smtp As New SmtpClient
' Send it
smtp.Host = SMTPServer.ToString
Try
smtp.Send(Message)
SendStatus = CType("OK", SqlString)
SMTPFullEmail = 0
Catch ex As Exception
SendStatus = CType(ex.Message, SqlString)
SMTPFullEmail = 1
End Try
End Function
End Class
Filed under: SQL Server