dbTalk Databases Forums  

Update connection in DTS package using VB

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Update connection in DTS package using VB in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
kristen
 
Posts: n/a

Default Update connection in DTS package using VB - 02-09-2004 , 10:55 PM






I'm trying to update all connections in all dts packages
on the server if the specified value is found in the
connection data source. The code seems to work fine as
in there are no unexpected errors or halts except that the
change doesn't actually occur. After the script runs
seemingly successfully, I open a package to confirm the
change but the connection still has the old data source!
Any thoughts????

'Connect to server and get a list of all packages
Set oDTSApp = New DTS.Application
Set oGetPkg = oDTSApp.GetPackageSQLServer(svr, uid, pwd,
auth)
Set cPkgs = oGetPkg.EnumPackageInfos("",
True, "") 'EnumPackageInfos
(PackageName,ReturnLatest,PackageID )
Set oGetPkg = Nothing

'Load each package and carry out the required changes
For Each oPkg In cPkgs
On Error GoTo ErrorHandler
pkgname = oPkg.Name
myPkg.LoadFromSQLServer svr, uid, pwd, auth, , , ,
pkgname

'Update connection datasource
Set cConns = myPkg.Connections
For Each oConn In cConns
If oConn.ConnectionProperties("Data Source")
= "WNCHASQ02" Then
oConn.ConnectionProperties("Data Source")
= "(local)"
Debug.Print myPkg.Name & ": " & oConn.Name
End If
Next
'Need to reset the package to be empty before the next
one begins
myPkg.UnInitialize
Set myPkg = Nothing
Next oPkg

Reply With Quote
  #2  
Old   
Olu Adedeji
 
Posts: n/a

Default RE: Update connection in DTS package using VB - 02-10-2004 , 02:56 AM






Looking at your code I cannot see anything wrong with it except (Goto ErrorHandler not defined in code, and vb property), does this actually work in DTS(ActiveXscript

possibility is scripting out dts packages use dtsdemo.exe into a text file *.bas then using REPLACE function in vbscript to search and replace with "(Local)" then use Vbscript to uncomment the line
[goPackage.SaveToSQLServer "(local)", "sa", ""]
and comment the line [goPackage.Execute] to save it iinstead of executing

rather long winded thoug


Reply With Quote
  #3  
Old   
Darren Green
 
Posts: n/a

Default Re: Update connection in DTS package using VB - 02-10-2004 , 03:12 AM



You are not saving your changes, so they will not persist beyond the
currently loaded instance of the package.

Try the Transfer Packages Sample Application here for an example you can
adapt-
Tools & Tasks
(http://www.sqldts.com/default.aspx?272)


--
Darren Green
http://www.sqldts.com


"kristen" <khodgesN (AT) SPAM (DOT) csr.com.au> wrote

Quote:
I'm trying to update all connections in all dts packages
on the server if the specified value is found in the
connection data source. The code seems to work fine as
in there are no unexpected errors or halts except that the
change doesn't actually occur. After the script runs
seemingly successfully, I open a package to confirm the
change but the connection still has the old data source!
Any thoughts????

'Connect to server and get a list of all packages
Set oDTSApp = New DTS.Application
Set oGetPkg = oDTSApp.GetPackageSQLServer(svr, uid, pwd,
auth)
Set cPkgs = oGetPkg.EnumPackageInfos("",
True, "") 'EnumPackageInfos
(PackageName,ReturnLatest,PackageID )
Set oGetPkg = Nothing

'Load each package and carry out the required changes
For Each oPkg In cPkgs
On Error GoTo ErrorHandler
pkgname = oPkg.Name
myPkg.LoadFromSQLServer svr, uid, pwd, auth, , , ,
pkgname

'Update connection datasource
Set cConns = myPkg.Connections
For Each oConn In cConns
If oConn.ConnectionProperties("Data Source")
= "WNCHASQ02" Then
oConn.ConnectionProperties("Data Source")
= "(local)"
Debug.Print myPkg.Name & ": " & oConn.Name
End If
Next
'Need to reset the package to be empty before the next
one begins
myPkg.UnInitialize
Set myPkg = Nothing
Next oPkg



Reply With Quote
  #4  
Old   
Kristen
 
Posts: n/a

Default Re: Update connection in DTS package using VB - 02-11-2004 , 09:02 PM



And there it is!

Thanks Darren!

It's always the simple things!

Quote:
-----Original Message-----
You are not saving your changes, so they will not persist
beyond the
currently loaded instance of the package.

Try the Transfer Packages Sample Application here for an
example you can
adapt-
Tools & Tasks
(http://www.sqldts.com/default.aspx?272)


--
Darren Green
http://www.sqldts.com


"kristen" <khodgesN (AT) SPAM (DOT) csr.com.au> wrote in message
news:d23801c3ef92$24fa8f50$a301280a (AT) phx (DOT) gbl...
I'm trying to update all connections in all dts packages
on the server if the specified value is found in the
connection data source. The code seems to work fine as
in there are no unexpected errors or halts except that
the
change doesn't actually occur. After the script runs
seemingly successfully, I open a package to confirm the
change but the connection still has the old data source!
Any thoughts????

'Connect to server and get a list of all packages
Set oDTSApp = New DTS.Application
Set oGetPkg = oDTSApp.GetPackageSQLServer(svr, uid, pwd,
auth)
Set cPkgs = oGetPkg.EnumPackageInfos("",
True, "") 'EnumPackageInfos
(PackageName,ReturnLatest,PackageID )
Set oGetPkg = Nothing

'Load each package and carry out the required changes
For Each oPkg In cPkgs
On Error GoTo ErrorHandler
pkgname = oPkg.Name
myPkg.LoadFromSQLServer svr, uid, pwd, auth, , , ,
pkgname

'Update connection datasource
Set cConns = myPkg.Connections
For Each oConn In cConns
If oConn.ConnectionProperties("Data Source")
= "WNCHASQ02" Then
oConn.ConnectionProperties("Data
Source")
= "(local)"
Debug.Print myPkg.Name & ": " &
oConn.Name
End If
Next
'Need to reset the package to be empty before the
next
one begins
myPkg.UnInitialize
Set myPkg = Nothing
Next oPkg


.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.