samliam
asked on
ConfigurationSettings - what's wrong?
This works:
String connString="localhost\\DBs erver; database=db; uid=sa; password=;";
.....
This doesn't:
in web.config:
<configuration>
<appSettings>
<add key="connString" value="localhost\\DBserver ; database=db; uid=sa; password=;" /add>
</appSettings>
in .cs:
using System.Configuration;
......
String connString=ConfigurationSe ttings.App Settings[" connString "];
......
Error: "SQL server does not exist or access denied."
So the problem might be because IIS grabs another web.config file.
I find 1 web.config under wwwroot\projectName. Others are under C:\program Files\MS Visual Studio .NET\....
How do I know if the program is reading from another web.config?
Thanks.
String connString="localhost\\DBs
.....
This doesn't:
in web.config:
<configuration>
<appSettings>
<add key="connString" value="localhost\\DBserver
</appSettings>
in .cs:
using System.Configuration;
......
String connString=ConfigurationSe
......
Error: "SQL server does not exist or access denied."
So the problem might be because IIS grabs another web.config file.
I find 1 web.config under wwwroot\projectName. Others are under C:\program Files\MS Visual Studio .NET\....
How do I know if the program is reading from another web.config?
Thanks.
ASKER
Sorry that was just a type here. I had it right in my code, i.e.e "/>" at the end. didn't work.
Replace "localhost\\DBserver" with "localhost\DBserver"
In the String \\ is an escaped \
In the String \\ is an escaped \
I normallu have connection strings in the following format
Server=localhost\DBserver; database=db; User Id=sa; pwd=;
I am not sure whether or not you need the escaped \ in the config file.
Server=localhost\DBserver;
I am not sure whether or not you need the escaped \ in the config file.
ASKER
it works.
However, if the String is defined in the c# code, one '\' does not work, it has to be '\\', while in web.config, it's the other way around.
explain?
However, if the String is defined in the c# code, one '\' does not work, it has to be '\\', while in web.config, it's the other way around.
explain?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you have made one small mistake in the configuration file.
<configuration>
<appSettings>
<add key="connString" value="localhost\\DBserver
</appSettings>
Replace the add tag with with & try.
<add key="connString" value="localhost\\DBserver
cheers!
Keshav.