ConfigurationSettings.AppSettings["value"] returns a string that starts with '@'

L

lauralucas

Hello

I'm trying to use a connection string stored in web.config

here is the web.config part

<appSettings>
<add key="NDDbase"
value="Server=SOMESERVER\\SOMEINSTANCE;integrated
security=SSPI;database=NDD"/>
</appSettings>

and from code I'm trying to access it like this:

string mySelectQuery = "SELECT * FROM sometable'";
string myConnectString = ConfigurationSettings.AppSettings["NDDbase"];

SqlCommand myCommand = new SqlCommand(mySelectQuery);
myCommand.Connection = new SqlConnection(myConnectString);


But when debugging, I see that myConnectString value always starts with
an @, like this:
@"Server=SOMESERVER\\SOMEINSTANCE;integrated
security=SSPI;database=NDD"

is this normal? I could parse the string and remove the at-sign but I
suppose is there for a reason. This makes the SqlConnection to not
open, as it is not initialized properly.

help me and write me some suggestions please, thanks =)

Regards
Laura Lucas
 
L

lauralucas

the answer:

It means that any backslash characters displayed aren't used for escape
purposes. For instance:

@"hello\tworld" is hello backslash tworld
whereas
"hello\tworld" is hello tab world

thanks



now that I look at it, the at-sign is not part of the string, look at
this picture:

http://i7.tinypic.com/20tgj08.jpg

weird, what does it mean?


Hello

I'm trying to use a connection string stored in web.config

here is the web.config part

<appSettings>
<add key="NDDbase"
value="Server=SOMESERVER\\SOMEINSTANCE;integrated
security=SSPI;database=NDD"/>
</appSettings>

and from code I'm trying to access it like this:

string mySelectQuery = "SELECT * FROM sometable'";
string myConnectString = ConfigurationSettings.AppSettings["NDDbase"];

SqlCommand myCommand = new SqlCommand(mySelectQuery);
myCommand.Connection = new SqlConnection(myConnectString);


But when debugging, I see that myConnectString value always starts with
an @, like this:
@"Server=SOMESERVER\\SOMEINSTANCE;integrated
security=SSPI;database=NDD"

is this normal? I could parse the string and remove the at-sign but I
suppose is there for a reason. This makes the SqlConnection to not
open, as it is not initialized properly.

help me and write me some suggestions please, thanks =)

Regards
Laura Lucas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top