0

I have a problem with the following connection string:

ConfigurationSettings.AppSettings["connstr"] = "Dsn=dsn_name; 
Trusted_Connection=yes;Uid=usrName;Pwd=some+Password;";

This throws an exception that authentication fails. The problem with that is the '+' sign inside the user password.

Anyone knows how can I escape special characters inside the password?

Thanks!

  • 1
    Try and use a ConnectionStringBuilder, see http://weblogs.asp.net/psheriff/archive/2009/09/08/using-the-connectionstringbuilder-class.aspx – Hans Kesting Feb 25 '13 at 15:31

1 Answers1

0

The point is, whole thing act as a string,Dsn=dsn_name; Trusted_Connection=yes;Uid=usrName;Pwd=some+Password; so, + act as a character, it does not act as concatenation.

string s = String.Format("Dsn={0}; 
Trusted_Connection=yes;Uid={1};Pwd={2}","dsn_name","usrName",some+"Password") ;

you can try String.Format method to inject string values to appropriate places. I am assunming that some is a string variable.

Then, assign s in the code.

ConfigurationSettings.AppSettings["connstr"] =s;

Edited: 1.Did you try bringing whole thing to a single line, if you separate it with a ; then there occurs a problem.

2.If this is a authentication failure in the first place, you have to check weather your password user name are correct. you have to add what ever your password after pwd=

diyoda_
  • 5,274
  • 8
  • 57
  • 89