Showing posts with label SSIS. Show all posts
Showing posts with label SSIS. Show all posts

Sunday, January 18, 2009

using SSIS for send out mail

Here's my code that uses both port and BCC:

fromAddress = New MailAddress("foo@bar.co.uk", "Database Mail")
toAddress = New MailAddress("somebody@somewhere.co.uk", "Data Group")
bccAddress = New MailAddress("somebody.else@somewhere.co.uk", "Data Group")

message = New MailMessage(fromAddress, toAddress)
messag.Bcc.Add(bccAddress)
message.Subject = "Data Mart Load Start"
message.Priority = MailPriority.High
message.IsBodyHtml = False
message.Body = "The Data Mart load process has started. Please exit all reporting systems until notified that the load process has completed."

smtpClient = New SmtpClient("mail.bar.co.uk", 2525)
smtpClient.Credentials = New System.Net.NetworkCredential("login", "password")
smtpClient.Send(message)
Dts.TaskResult = Dts.Results.Success

Thursday, January 15, 2009

SSIS Nugget: RetainSameConnection property of the OLE DB Connection Manager

SSIS Nugget: RetainSameConnection property of the OLE DB Connection Manager

Did you know....

...that you can run regular SQL Server transactions in SSIS over multiple tasks without requiring the use of Distributed Transaction Coordinator (DTC)? Well I didn't but thanks to that man again, Kirk Haselden, I do now.

The default behaviour of a Connection Manager is that every task has its own connection which is why they are so named and not simply named "Connection" as in DTS2000. The RetainSameConnection property on the OLE DB Connection Manager enables you to run multiple tasks against SQL Server all within 1 SQL Server transaction if its RetainSameConnection property equals TRUE. That means that you can BEGIN TRANSACTION in one Execute SQL Task and then choose to COMMIT or ROLLBACK in another one. You can even enlist data-flows in that transaction as well!

Allow me to demonstrate.

Here's my package.

20050820ControlFlow.JPG


In the first Execute SQL Task I create myself a table and begin a transaction.

20050820BeginTran.JPG


The data-flow inserts some data into that table.

20050820DataFlow.JPG


And the second Execute SQL Task rolls back the transaction.

20050820RollbackTran.JPG

If you check the table afterwards.....there's nothing in it!

Have a go - you can download the package from here: http://blogs.conchango.com/Admin/ImageGallery/blogs.conchango.com/jamie.thomson/20050820RetainSameConnection.zip


Here was me thinking you could only run transactions either within the same Execute SQL Task or else using distributed transactions. There's just always something new to learn about this thing isn't there!!!