Solved

ConfigurationSettings - what's wrong?

Posted on 2003-11-12
6
577 Views
Last Modified: 2010-04-16
This works:

String connString="localhost\\DBserver; 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=ConfigurationSettings.AppSettings["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.

0
Comment
Question by:samliam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:keshavap
ID: 9737850
Hello,

you have made one small mistake in the configuration file.

<configuration>
  <appSettings>
     <add key="connString" value="localhost\\DBserver; database=db; uid=sa; password=;" /add>
  </appSettings>

Replace the add tag with with & try.
<add key="connString" value="localhost\\DBserver; database=db; uid=sa; password=;" />

cheers!
Keshav.
0
 

Author Comment

by:samliam
ID: 9738248
Sorry that was just a type here. I had it right in my code, i.e.e "/>" at the end. didn't work.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9740540
Replace "localhost\\DBserver" with "localhost\DBserver"
In the String \\ is an escaped \
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:sedmans
ID: 9741087
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.
0
 

Author Comment

by:samliam
ID: 9741608
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?
0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 50 total points
ID: 9747240
You have two options in string parsing in C#:
Standard is C++ string parsing where escaped characters like <CR> and <LF> are written as \r and \n. If you want to write a backslash then you have to double it.
When you set an "@" in front of the string you switch to VB string parsing where you need to double the quotes place a single quote in the string else the string is terminated.

So you can write either:
String connString=@"localhost\DBserver; database=db; uid=sa; password=;";
or
String connString="localhost\\DBserver; database=db; uid=sa; password=;";

The result is the same. It depends on the string if it's easier to use the VB-style or C++-style. I prefer VB-style for filepaths.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question