[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ConfigurationSettings - what's wrong?

Posted on 2003-11-12
6
Medium Priority
?
579 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

656 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