dbTalk Databases Forums  

Changing an exisitng connection dynamically

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


Discuss Changing an exisitng connection dynamically in the microsoft.public.sqlserver.dts forum.



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

Default Changing an exisitng connection dynamically - 11-15-2005 , 10:06 PM






In AxctiveX Script I was dynamically changing the server and database of an
existing connection as I was looping through a recordset and then executing a
SQL Task that was set to that exisitng Connection (see code example below).

Everthing worked beautifully as long as I was switching databases
(oCnn.Catalog) within the same Server (oCnn.DataSource). I could change to 3
different databases on the same server and everything worked, but as soon as
I tried to change the server and the database it would fail. Is there any
way in code to reset the server (oCnn.DataSource) of an exisitng connection
so that I can change servers?

Code Example:

Set rs=DTSGlobalVariables("gvRS").Value
If rs.RecordCount>0 then
Do Until rs.EOF=True
'Set up Destination Output Server & Database Connection
set oCnn = DTSGlobalVariables.Parent.Connections("OutputServe r")
oCnn.DataSource =rs("SERVER_NAME")
oCnn.Catalog =rs("DATABASE_NAME")

'Enable the existing step (Execute SQL Task) and run the SQL
set oStep = DTSGlobalVariables.Parent.Steps("TruncateOutputAID ata")
oStep.DisableStep=False
oStep.Execute
oStep.DisableStep=True

rs.MoveNext
Loop

Every idea I have come up with to work around this problem has failed. I
appreciate any help I can get!

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Changing an exisitng connection dynamically - 11-16-2005 , 12:49 AM






What was the error message?



"JSP" <JSP (AT) discussions (DOT) microsoft.com> wrote


Quote:
In AxctiveX Script I was dynamically changing the server and database of
an
existing connection as I was looping through a recordset and then
executing a
SQL Task that was set to that exisitng Connection (see code example
below).

Everthing worked beautifully as long as I was switching databases
(oCnn.Catalog) within the same Server (oCnn.DataSource). I could change
to 3
different databases on the same server and everything worked, but as
soon as
I tried to change the server and the database it would fail. Is there
any
way in code to reset the server (oCnn.DataSource) of an exisitng
connection
so that I can change servers?

Code Example:

Set rs=DTSGlobalVariables("gvRS").Value
If rs.RecordCount>0 then
Do Until rs.EOF=True
'Set up Destination Output Server & Database Connection
set oCnn = DTSGlobalVariables.Parent.Connections("OutputServe r")
oCnn.DataSource =rs("SERVER_NAME")
oCnn.Catalog =rs("DATABASE_NAME")

'Enable the existing step (Execute SQL Task) and run the SQL
set oStep = DTSGlobalVariables.Parent.Steps("TruncateOutputAID ata")
oStep.DisableStep=False
oStep.Execute
oStep.DisableStep=True

rs.MoveNext
Loop

Every idea I have come up with to work around this problem has failed.
I
appreciate any help I can get!


Reply With Quote
  #3  
Old   
JSP
 
Posts: n/a

Default Re: Changing an exisitng connection dynamically - 11-16-2005 , 04:21 PM



Hi,

The message was:

Step Error Source: Microsoft OLE DB Provider for SQL Server
Step Error Description:Could not locate entry in sysdatabases for database
'AgencyDataRepositoryJulie'. No entry found with that name. Make sure that
the name is entered correctly.
Step Error code: 80004005

The step is pointing to the existing connection that I changed the server
(oCnn.DataSource) in, in the code as shown in my example. The interesting
thing is if you run the job interactively and stop and look at the exisitng
connection the new entries that I made in code are there (and the server and
database exist). But what it appears to me is that even though the server
connection changed when I display the vaues in the disconnected edit of the
connection, the actual system performing the code does not seem to release
the connection and is still looking at the first server that was there not
the new one that I changed to. The Database "'AgencyDataRepositoryJulie"
that the error was referring to does exist on the server I was changing to
but does not exist on the previous server connection.

Any ideas on how to to force the system to update the existing connection?

JSP

"Allan Mitchell" wrote:

Quote:
What was the error message?



"JSP" <JSP (AT) discussions (DOT) microsoft.com> wrote in message
news:0BB9E776-1B4F-4272-970E-3750429637E6 (AT) microsoft (DOT) com:

In AxctiveX Script I was dynamically changing the server and database of
an
existing connection as I was looping through a recordset and then
executing a
SQL Task that was set to that exisitng Connection (see code example
below).

Everthing worked beautifully as long as I was switching databases
(oCnn.Catalog) within the same Server (oCnn.DataSource). I could change
to 3
different databases on the same server and everything worked, but as
soon as
I tried to change the server and the database it would fail. Is there
any
way in code to reset the server (oCnn.DataSource) of an exisitng
connection
so that I can change servers?

Code Example:

Set rs=DTSGlobalVariables("gvRS").Value
If rs.RecordCount>0 then
Do Until rs.EOF=True
'Set up Destination Output Server & Database Connection
set oCnn = DTSGlobalVariables.Parent.Connections("OutputServe r")
oCnn.DataSource =rs("SERVER_NAME")
oCnn.Catalog =rs("DATABASE_NAME")

'Enable the existing step (Execute SQL Task) and run the SQL
set oStep = DTSGlobalVariables.Parent.Steps("TruncateOutputAID ata")
oStep.DisableStep=False
oStep.Execute
oStep.DisableStep=True

rs.MoveNext
Loop

Every idea I have come up with to work around this problem has failed.
I
appreciate any help I can get!



Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Changing an exisitng connection dynamically - 11-17-2005 , 12:23 AM



Have you looked at the "Close Connection On Completion" workflow
property?

"JSP" <JSP (AT) discussions (DOT) microsoft.com> wrote


Quote:
Hi,

The message was:

Step Error Source: Microsoft OLE DB Provider for SQL Server
Step Error Description:Could not locate entry in sysdatabases for
database
'AgencyDataRepositoryJulie'. No entry found with that name. Make sure
that
the name is entered correctly.
Step Error code: 80004005

The step is pointing to the existing connection that I changed the
server
(oCnn.DataSource) in, in the code as shown in my example. The
interesting
thing is if you run the job interactively and stop and look at the
exisitng
connection the new entries that I made in code are there (and the server
and
database exist). But what it appears to me is that even though the
server
connection changed when I display the vaues in the disconnected edit of
the
connection, the actual system performing the code does not seem to
release
the connection and is still looking at the first server that was there
not
the new one that I changed to. The Database
"'AgencyDataRepositoryJulie"
that the error was referring to does exist on the server I was changing
to
but does not exist on the previous server connection.

Any ideas on how to to force the system to update the existing
connection?

JSP

"Allan Mitchell" wrote:


What was the error message?



"JSP" <JSP (AT) discussions (DOT) microsoft.com> wrote in message
news:0BB9E776-1B4F-4272-970E-3750429637E6 (AT) microsoft (DOT) com:


In AxctiveX Script I was dynamically changing the server and
database of
an
existing connection as I was looping through a recordset and then
executing a
SQL Task that was set to that exisitng Connection (see code example
below).

Everthing worked beautifully as long as I was switching databases
(oCnn.Catalog) within the same Server (oCnn.DataSource). I could
change
to 3
different databases on the same server and everything worked, but as
soon as
I tried to change the server and the database it would fail. Is
there
any
way in code to reset the server (oCnn.DataSource) of an exisitng
connection
so that I can change servers?

Code Example:

Set rs=DTSGlobalVariables("gvRS").Value
If rs.RecordCount>0 then
Do Until rs.EOF=True
'Set up Destination Output Server & Database Connection
set oCnn = DTSGlobalVariables.Parent.Connections("OutputServe r")
oCnn.DataSource =rs("SERVER_NAME")
oCnn.Catalog =rs("DATABASE_NAME")

'Enable the existing step (Execute SQL Task) and run the SQL
set oStep = DTSGlobalVariables.Parent.Steps("TruncateOutputAID ata")
oStep.DisableStep=False
oStep.Execute
oStep.DisableStep=True

rs.MoveNext
Loop

Every idea I have come up with to work around this problem has
failed.
I
appreciate any help I can get!





Reply With Quote
  #5  
Old   
JSP
 
Posts: n/a

Default Re: Changing an exisitng connection dynamically - 11-17-2005 , 07:12 PM



Thanks it worked! I set the last SQL Task in the loop to "Close Connection
On Completion" and then in the next loop checked the connection:

If oCnn.Connected=False then oCnn.ConnectImmediate=True
End If

This worked perfectly and swithed servers as needed. Thanks again!

JSP
"Allan Mitchell" wrote:

Quote:
Have you looked at the "Close Connection On Completion" workflow
property?

"JSP" <JSP (AT) discussions (DOT) microsoft.com> wrote in message
news:F03F1713-5C53-4F2D-9055-E7C7452BAE75 (AT) microsoft (DOT) com:

Hi,

The message was:

Step Error Source: Microsoft OLE DB Provider for SQL Server
Step Error Description:Could not locate entry in sysdatabases for
database
'AgencyDataRepositoryJulie'. No entry found with that name. Make sure
that
the name is entered correctly.
Step Error code: 80004005

The step is pointing to the existing connection that I changed the
server
(oCnn.DataSource) in, in the code as shown in my example. The
interesting
thing is if you run the job interactively and stop and look at the
exisitng
connection the new entries that I made in code are there (and the server
and
database exist). But what it appears to me is that even though the
server
connection changed when I display the vaues in the disconnected edit of
the
connection, the actual system performing the code does not seem to
release
the connection and is still looking at the first server that was there
not
the new one that I changed to. The Database
"'AgencyDataRepositoryJulie"
that the error was referring to does exist on the server I was changing
to
but does not exist on the previous server connection.

Any ideas on how to to force the system to update the existing
connection?

JSP

"Allan Mitchell" wrote:


What was the error message?



"JSP" <JSP (AT) discussions (DOT) microsoft.com> wrote in message
news:0BB9E776-1B4F-4272-970E-3750429637E6 (AT) microsoft (DOT) com:


In AxctiveX Script I was dynamically changing the server and
database of
an
existing connection as I was looping through a recordset and then
executing a
SQL Task that was set to that exisitng Connection (see code example
below).

Everthing worked beautifully as long as I was switching databases
(oCnn.Catalog) within the same Server (oCnn.DataSource). I could
change
to 3
different databases on the same server and everything worked, but as
soon as
I tried to change the server and the database it would fail. Is
there
any
way in code to reset the server (oCnn.DataSource) of an exisitng
connection
so that I can change servers?

Code Example:

Set rs=DTSGlobalVariables("gvRS").Value
If rs.RecordCount>0 then
Do Until rs.EOF=True
'Set up Destination Output Server & Database Connection
set oCnn = DTSGlobalVariables.Parent.Connections("OutputServe r")
oCnn.DataSource =rs("SERVER_NAME")
oCnn.Catalog =rs("DATABASE_NAME")

'Enable the existing step (Execute SQL Task) and run the SQL
set oStep = DTSGlobalVariables.Parent.Steps("TruncateOutputAID ata")
oStep.DisableStep=False
oStep.Execute
oStep.DisableStep=True

rs.MoveNext
Loop

Every idea I have come up with to work around this problem has
failed.
I
appreciate any help I can get!






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.