Forum Discussion
How to set environment variables for sql server process running on windows
Thanks for your reply
My requirement is just to put one environment variable in the sql server process for example "MY_SQL_SERVER_PORT=1434"
In linux processes we can find the process environment variables under "/proc/1475/environ" .Similar way windows should have something right? I want to set a custom environment variable there.Is that possible in sql server process which is running on windows machine?
If you add the environment variable to the system environment variable table then all processes will see it listed.
But as I say, taking that approach can just lead to failure if the server configuration changes but the nobody manually changes the environment variable to match the new setting.
If you're expecting SQL Server to maintain the value, that's not going to happen, as SQL Server does not keep such data in the system environment table at all.
On the Windows host, if you go to Control Panel > System, and then (depending on your Windows version) possibly > Advanced system settings, you'll get to the following dialog which is where you can add a system variable.
There's not much point in trying to compare Linux to Windows.
Cheers,
Lain
- joicejoyAug 08, 2023Copper Contributor
I do not want to set the environment variable globally like you said via system environment variable.I have two sql server process running on the same machine on 2 different ports , so my need is like setting the environment variable for each sql server process manually with different value.
for example : sql server instance1 process>>>MY_SQL_SERVER_PORT = 1433
sql server instance2 process>>>MY_SQL_SERVER_PORT = 1434
If its not possible then no point in discussing further.Thank you for the prompt reply LainRobertson
- LainRobertsonAug 08, 2023Silver Contributor
Setting it per process is possible if specific requirements are met, but it's complicated and comes with knock-on issues.
Practically-speaking, your requested approach isn't possible. You either fetch the real data from the registry or go without.
Cheers,
Lain