SQL Server Agent can't see environment variables  
Author Message
Djangar





PostPosted: Mon Jul 28 11:46:17 CDT 2003 Top

SQL Server Developer >> SQL Server Agent can't see environment variables

Hi,

It seems stop/starting the service is not enough to have SQL Server Agent
use any newly set Environment Variables. We have to reboot the machine
in order for the Environment Variables to be 'seen'.

Is there a less drastic way to get SQL Server Agent to update it's
Environment Variables ?

We are writing an installer that needs to add some environment variables
and then submit some jobs on the SQL Server Agent. Currently it fails
because it cannot see the Enviroment Variables.

During some manual testing, we found that rebooting fixed the problem
and suddenly SQL Server Agent could see the Environment Variables.

OS: Win2k Server + SP3
DB: SQL 2000 + SP3

Regards

Nick

SQL Server264  
 
 
bruce





PostPosted: Mon Jul 28 11:46:17 CDT 2003 Top

SQL Server Developer >> SQL Server Agent can't see environment variables all nt services (SQL Agent included) inherit their Environment Variables
from the services control manager (services.exe). while you might be able
to shutdown all services, kill services.exe and restart it and its services,
a reboot is safer and probably just as quick.

-- bruce (sqlwork.com)



> Hi,
>
> It seems stop/starting the service is not enough to have SQL Server Agent
> use any newly set Environment Variables. We have to reboot the machine
> in order for the Environment Variables to be 'seen'.
>
> Is there a less drastic way to get SQL Server Agent to update it's
> Environment Variables ?
>
> We are writing an installer that needs to add some environment variables
> and then submit some jobs on the SQL Server Agent. Currently it fails
> because it cannot see the Enviroment Variables.
>
> During some manual testing, we found that rebooting fixed the problem
> and suddenly SQL Server Agent could see the Environment Variables.
>
> OS: Win2k Server + SP3
> DB: SQL 2000 + SP3
>
> Regards
>
> Nick
>
>


 
 
David





PostPosted: Mon Jul 28 11:48:36 CDT 2003 Top

SQL Server Developer >> SQL Server Agent can't see environment variables


> Hi,
>
> It seems stop/starting the service is not enough to have SQL Server Agent
> use any newly set Environment Variables. We have to reboot the machine
> in order for the Environment Variables to be 'seen'.
>
> Is there a less drastic way to get SQL Server Agent to update it's
> Environment Variables ?

You will need to run code altering the environment from inside the Agent
process.

You could try running a job containing some script like

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Set WshProcEnv = WshShell.Environment("PROCESS")
WshProcEnv("MY_ENV") = WshSysEnv("MY_ENV")

To read from the system environment and write to the process's environment.

Or invoke a dll that does the same thing using win32 calls.

NB an executable won't work. The the code must run in the agent's process,
not a process that the agent spawns.


David