0

I'm connecting to a database using ODBC in my ASP.Net application where the password is something along the lines of:

pwd=abc"123

When I create the connection in my server explorer, it lets me put in the username and password and when I push the Test Connection button, it says the connection is successful. But when I hit the OK button, I get a bunch of errors along the lines of:

ERROR [28000] ... Invalid Password
ERROR [xxxxx] ... Invalid attribute in connection string: xxx

So, I decided to create my own connection string and place it in my web.config file manually.

Based upon suggestions from this solution, the connection string I created looks as follows:

<add name="ConnectionString" connectionString="Dsn=xxxx;...uid=xxxx;pwd='abc&quot;123'"

I've tried a few other alternatives such as:

  • Removing the ' character surrounding the pwd
  • Replacing the ' characters also by &quot;
  • Replacing &quot; with &#34;

But none of these solutions are working for me.

And I know this is where the issue is coming from, because when I change the username and password to one that does not have a character that needs to be escaped, the application runs.

How can I get this password set correctly?

Community
  • 1
  • 1
John Bustos
  • 19,036
  • 17
  • 89
  • 151
  • Are the single quotes around the password necessary? Are they causing the problem? – heijp06 Nov 20 '14 at 20:40
  • Can you put a breakpoint in your application to see the value you are getting by the time your application is trying to connect? – Kevin DiTraglia Nov 20 '14 at 20:41
  • you don't need the single quote in there.. you were close..I posted an answer that should do the trick – MethodMan Nov 20 '14 at 20:41
  • @DJKRAZE `Removing the ' character surrounding the pwd` is listed as the first thing he tried – Kevin DiTraglia Nov 20 '14 at 20:42
  • Yeah, sorry @DJKraze, it didn't work... :( – John Bustos Nov 20 '14 at 20:42
  • look at my updated answer I added &quot" – MethodMan Nov 20 '14 at 20:43
  • @KevinDiTraglia, that's an awesome idea!! - I know this is going to sound stupid as all geddout, but where would that breakpoint go for an asp.net webforms application to see what the connection string is?? – John Bustos Nov 20 '14 at 20:44
  • Did you try to put the whole connectionstring between single quotes and leave the double quote as is in the password? – Steve Nov 20 '14 at 20:46
  • @Steve, it won't even let me do that, I get an error because the quote is read as a quote character and breaks the XML... I tried, though, wrapping the whoel connection string in single quotes and leavign the `"`, but that didn't work either... – John Bustos Nov 20 '14 at 20:50
  • I updated my answer to escape the quotes by adding `;;` at the end try that – MethodMan Nov 20 '14 at 20:51
  • 2
    I mean _connectionstring='xxxxxxxx;pwd=123"abc;xxxxx'_ without single quotes around the password – Steve Nov 20 '14 at 20:55
  • only other option based on where you got your solution from is to use `Steve's` example or change the damn password to not have quotes as a character..sorry.. – MethodMan Nov 20 '14 at 20:59
  • @Steve, that makes good sense, trying now... thank you!! – John Bustos Nov 20 '14 at 21:03
  • @DJKRAZE, **THANK YOU SOOO MUCH** for trying so hard... It's just driving me nuts!!! – John Bustos Nov 20 '14 at 21:03
  • not a problem I think that Steve's suggestion will work.. I never use quotes as a character for passwords.. that's why I suggested the `&quot` C# is very funny about escape characters – MethodMan Nov 20 '14 at 21:06
  • Sadly, @Steve, great idea, but still did not work... I'm at wits' end and just think I'm going to have no choice but have the DB admin change the password.... THERE HAS TO BE ANOTHER WAY!!!! – John Bustos Nov 20 '14 at 21:22
  • 1
    Just for info, what kind of database are you connecting to? The solution proposed in your question link should work with Sql Server – Steve Nov 20 '14 at 21:34
  • Yeah, @Steve, it's not a well known DB type... It's one of those archaic ones you have to use generic odbc drivers to access... – John Bustos Nov 20 '14 at 21:42
  • 1
    I am sorry but I am not able to help you. There this allarming note on [www.connectionstrings.com](http://www.connectionstrings.com/formating-rules-for-connection-strings/) about the formatting rules for the connectionstrings. – Steve Nov 20 '14 at 21:45

0 Answers0