DataContext.Connection.ConnectionString – No Password

My favourite way to clean up database tables is with a little stored procedures that runs from an async database command. It is a bit old fashioned but LinqToSql does not have any built-in async support. I want avoid that the clean-up tasks uses processing time of my application.

To create the async command I need the current connection string and add the ASYNC=True value. Easy, I thought. I take the DataContext.Connection.ConnectionString, use it to instantiate a ConnectionStringBuilder and set the Async property. This worked fine as long as I was running with SSI. When I changed to SQL server login I got this error: Error: 18456, Severity: 14, State: 8.

This means that the password is incorrect. That proved to be absolutely correct. The ConnectionString property does not return the password and this is not mentioned in the MSDN.

1 thought on “DataContext.Connection.ConnectionString – No Password

  1. I noticed that DataContext.Connection.ConnectionString *does* seem to preserve the password until you actually use the DataContext to access the database. One workaround I’m using is to squirrel away DataContext.Connection.ConnectionString in the OnCreate() while it still includes the password.

    Thanks for your blog entry!

Leave a Reply

Your email address will not be published. Required fields are marked *