How to clear collection within the memory?

PiggyZhou

Member
Joined
Aug 22, 2008
Messages
5
Programming Experience
Beginner
Hi, all here,
Hope the title is clear for your help.
I am having a problem with loading DTS packages from a SQL Server 2000 instance within a loop I established. What I am trying to do here is to load all packegs from that SQL Server 2000 instance and save them all to other instance. The problem now is : as there is the same task name for different DTS packages thus e.g. after loading the first DTS package, I save it to another instance, and then loop it through the source server instance and trying to load the next DTS package from that server instance, but because the second DTS package it is loading got the same names for some tasks as the first DTS package got, therefore during the execution it throws the error message telling that: step 'step_name' already exists in the collection. It seems like the computer is loading all the DTS packages into a memory until the connection with the server instance is closed and it does not allow duplicate names for whatever objects it saved into the memory within the collection? But in my case it is not allowed to change the tasks names within each DTS package, thus it seems like in order to loop through the source instance to load all DTS packages, the only thing we can try is to clear the collection after each iteration within the loop?
The statement I am using to load the DTS package is : Opkg.LoadFromSQLServer("servername", "user_name", "password", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, "", "", "", Package_name)Can any experts here give me any ideas of how to clear that so-called collection within the memory to enable the loading of the next package from the source server instance if there is any way of achieving it?
Thanks a lot in advance and I am looking forward to hearing from you for your kind help and advices.
With best regards,
Yours sincerely,
 
To answer my own question, what I have tried and it works perfectly now is :
I unload the package after saving it to another place and then declare a new DTS package variable, assign the new blank DTS package variable to the old one, and then loop again with the following code lines:


Opkg.UnInitialize()
Opkg = Nothing
Dim Opkg1 As DTS.Package = New DTS.Package()
Opkg = Opkg1

The loop going through all available DTS packages on the server work fine now.

Hope it helps to anyone here who is in the same situation and looking for a solution to it.
Best regards,
 
Back
Top