dbTalk Databases Forums  

@@ServerName for Global Variable

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


Discuss @@ServerName for Global Variable in the microsoft.public.sqlserver.dts forum.



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

Default @@ServerName for Global Variable - 12-09-2005 , 08:54 AM






Howdy all. My goal here is to be able to be able to move a DTS Package from
one box to another and not have to specify the new box name in the DB
connections. I know I can do it in the Global Variables under Package
properties, but that's not all that great either.

Therefore I try to assign the value of @@ServerName to a GV, but it's not
working as expected. I have a GV named gvBoxName, and in the Dynamic
Properties Task I use the Query option and assign the Data Source value(under
the DB connection) to "select @@ServerName". All seems good as the Package
works with success. But then I "save as" to save the Package to another box.
I then exec the Package from the new box but it's still running against the
old box. Is there a way to either make this work or something that will
accomplish the same goal?
--
TIA,
ChrisR

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

Default Re: @@ServerName for Global Variable - 12-12-2005 , 02:08 AM






ChrisR wrote:
Quote:
Howdy all. My goal here is to be able to be able to move a DTS Package from
one box to another and not have to specify the new box name in the DB
connections. I know I can do it in the Global Variables under Package
properties, but that's not all that great either.

Therefore I try to assign the value of @@ServerName to a GV, but it's not
working as expected. I have a GV named gvBoxName, and in the Dynamic
Properties Task I use the Query option and assign the Data Source value(under
the DB connection) to "select @@ServerName". All seems good as the Package
works with success. But then I "save as" to save the Package to another box.
I then exec the Package from the new box but it's still running against the
old box. Is there a way to either make this work or something that will
accomplish the same goal?
To run the query "SELECT @@SERVERNAME", you need a SQL connection, so
using that to change the connection, which is required to run the query
in the first place does not make much sense.

Perhaps you could use the name localhost.

Realisitically if you have machines with named instances and such like
you can expect to have to set this from outside the package. I do this
with my packages. They run as scheduled jobs, and the job passes in the
server name through DTSRUN and /A to set a global variable.

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


Reply With Quote
  #3  
Old   
David Portas
 
Posts: n/a

Default Re: @@ServerName for Global Variable - 12-12-2005 , 09:16 AM



ChrisR wrote:
Quote:
Howdy all. My goal here is to be able to be able to move a DTS Package from
one box to another and not have to specify the new box name in the DB
connections. I know I can do it in the Global Variables under Package
properties, but that's not all that great either.

Therefore I try to assign the value of @@ServerName to a GV, but it's not
working as expected. I have a GV named gvBoxName, and in the Dynamic
Properties Task I use the Query option and assign the Data Source value(under
the DB connection) to "select @@ServerName". All seems good as the Package
works with success. But then I "save as" to save the Package to another box.
I then exec the Package from the new box but it's still running against the
old box. Is there a way to either make this work or something that will
accomplish the same goal?
--
TIA,
ChrisR
@@SERVERNAME is a TSQL function so a connection to the server is
required before it can even work.

You can create a connection that uses a UDL (Data Link) file. Check the
option "Always read properties from UDL file". You then need to ensure
that the UDL is located in the same path on each server.

Depending on how the package is run it may make sense to pass the
server name from the calling code by assigning a global variable.

If you run the package on the server and you think you'll only ever use
a default instance then you can specify localhost as server name. I'd
recommend you avoid doing that in most cases however, because it limits
your options for re-deploying with virtual instances at a later data.

--
David Portas
SQL Server MVP
--



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

Default Re: @@ServerName for Global Variable - 12-12-2005 , 12:58 PM



Darren Green wrote:
Quote:
ChrisR wrote:

Howdy all. My goal here is to be able to be able to move a DTS Package
from one box to another and not have to specify the new box name in
the DB connections. I know I can do it in the Global Variables under
Package properties, but that's not all that great either.
Therefore I try to assign the value of @@ServerName to a GV, but it's
not working as expected. I have a GV named gvBoxName, and in the
Dynamic Properties Task I use the Query option and assign the Data
Source value(under the DB connection) to "select @@ServerName". All
seems good as the Package works with success. But then I "save as" to
save the Package to another box. I then exec the Package from the new
box but it's still running against the old box. Is there a way to
either make this work or something that will accomplish the same goal?


To run the query "SELECT @@SERVERNAME", you need a SQL connection, so
using that to change the connection, which is required to run the query
in the first place does not make much sense.

Perhaps you could use the name localhost.

Realisitically if you have machines with named instances and such like
you can expect to have to set this from outside the package. I do this
with my packages. They run as scheduled jobs, and the job passes in the
server name through DTSRUN and /A to set a global variable.

You could also maintain an alias name, see Client Network Utility, and
code that in your packages. May help, unless you have more than one
instance per machine.

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


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

Default Re: @@ServerName for Global Variable - 12-26-2005 , 02:56 PM



Hello.

Is it possible to obtain the Windows server name the DTS package is
running on dynamically from within the package? TSQL will not work for
me (@@SERVERNAME) because it requires a predetemined connection. So
it should be some sort of DTS/ActiveX Script magic.

Is it possible to use Win32 from these ActiveX Task objects?

Thank you in advance!


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.