passing %COMPUTERNAME% in SQL Connection string?

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
Provider=SQLOLEDB.1;Persist Security Info=True;User ID=XXXXX;Initial Catalog=CLS;Data Source=SQL;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=%COMPUTERNAME%;Use Encryption for Data=False;Tag with column collation when possible=False

I have the above connection string to connect to SQL.
However, when it connects the "Workstation ID=" literally shows up as "%COMPUTERNAME%" and not the actual name of the computer calling the connection string.

Is there anyway to get the system variable to dynamically pull in the string?
 

ForumMaster

Diamond Member
Feb 24, 2005
7,792
1
0
i don't think you'll be able to do like this. %COMPUTERNAME% is an environment variable.

perhaps you can do this:

"Provider=SQLOLEDB.1;Persist Security Info=True;User ID=XXXXX;Initial Catalog=CLS;Data Source=SQL;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID="+
System.Environment.GetEnvironmentVariable("COMPUTERNAME", EnvironmentVariableTarget.Machine)+
";Use Encryption for Data=False;Tag with column collation when possible=False"

if that doesn't work, call the function first into a variable, then concatenate the variable is a similar fashion. otherwise you'll get a literal "%COMPUTERNAME%" instead of the value.

link
 

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
what you pasted didn't work, but I'm reading the link now and trying to make heads or tails of it.
 

KLin

Lifer
Feb 29, 2000
30,951
1,079
126
What programming language are we talking about?
 
Last edited:

Evadman

Administrator Emeritus<br>Elite Member
Feb 18, 2001
30,990
5
81
It depends on the programming language. the connection string is exactly that, a string. Whatever string builder you are using needs to pull the computer name and insert it into the string.
 

KIAman

Diamond Member
Mar 7, 2001
3,342
23
81
Why do you need workstation ID in the connection string? Are you actually using the host information in the SQL server? Also user id but no password?

That junk looks like a typical connection string builder output.