Home > Archive > MS SQL Server DTS > July 2005 > How to do a mass change in the email specified in DTS: Send Mail T









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to do a mass change in the email specified in DTS: Send Mail T
SQL Junior

2005-07-19, 7:24 am

for DTS PackageHi

I have created many DTS Packages that use Send Mail Task to send email to
abc@test.com, how can I change them to abc@test1.com without manually
changing it (too tedious). Is there any like replace function or utility for
DTS Package that can replace test.com to test1.com.

Thanks for any advice
Darren Green

2005-07-20, 8:24 pm

In message <457E1827-A22C-41E8-9578- 3FB70B4AC976@microso
ft.com>, SQL
Junior <SQL@Junior.?.microsoft.com.invalid> writes
>for DTS PackageHi
>
>I have created many DTS Packages that use Send Mail Task to send email to
>abc@test.com, how can I change them to abc@test1.com without manually
>changing it (too tedious). Is there any like replace function or utility for
>DTS Package that can replace test.com to test1.com.
>
>Thanks for any advice



Write some code like this, (not checked).

Enumerate packages, loading each one. Enumerate tasks, looking for send
mail tasks. Grab the custom task object and set the to address.


Dim oDTSApp As DTS.Application
Dim oPkgSQLServer As DTS.PackageSQLServer
Dim oPkgInfos As DTS.PackageInfos
Dim oPkgInfo As DTS.PackageInfo
Dim oPkg As DTS.Package2
Dim oTask As DTS.Task2
Dim oMailTask As SendMailTask

' Enumerate Packages
Set oDTSApp = New DTS.Application
Set oPkgSQLServer = oDTSApp. GetPackageSQLServer(
"SourceServer", "",
"", DTSSQLStgFlag_UseTru
stedConnection)
Set oPkgInfos = oPkgSQLServer.EnumPackageInfos("", True, "")

' Loop through Packages
Set oPkgInfo = oPkgInfos.Next
' "Column does not exist" error on SQL 7.0 because sysdtspackages
lacks packagetype column

Do While Not oPkgInfos.EOF
Set oPkg = New DTS.Package2

' Load the Pkg
oPkg.LoadFromSQLServer "SourceServer", "", "",
DTSSQLStgFlag_UseTru
stedConnection, "", "", "", oPkgInfo.Name

' Change SQL Connections
For Each oTask In oPkg.Tasks
If oTask.CustomTaskID = "DTSSendMailTask" Then
Set oMailTask = oTask.CustomTask
oMailTask.ToLine = "spam@sqldts.com"
End If
Next

' Save the Pkg
oPkg.SaveToSQLServer "DestServer", "", "",
DTSSQLStgFlag_UseTru
stedConnection

oPkg.UnInitialize

Set oPkgInfo = oPkgInfos.Next
Loop


' Clean Up
Set oMailTask = Nothing
Set oTask = Nothing
Set oPkg = Nothing
Set oPkgInfo = Nothing
Set oPkgInfos = Nothing
Set oPkgSQLServer = Nothing
Set oDTSApp = Nothing

--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com