I’m working on a WinForm application. I’ve implemented data-access logic into a “library project” that I set as reference in my WinForm project. I’m using LINQ to SQL to connect to my project database, mapping the tables I use into a dbml file. Now I have to publish my project and change the connection string to point to the production DB.
Is it possible to change the connection string without re-compile the project?
It’ll be very useful at debug-time and for maintenance…
I’ve tried to change it in app.config and also in the Settings file, but it seems to still point to the development DB.
Where am I doing wrong?
The solution suggested in this article is very good: http://goneale.com/2009/03/26/untie-linq-to-sql-connection-string-from-application-settings/
But I decided to solve my issue in a different way.
Without modifying anyting in the
dbmlfile I added in my DAO class a constructor that takes a parameter:then instead of using
DataClasses()constructor to instantiate the LINQ-TO-SQL class, I replaced it withDataClasses(_connString).Now I can use the data access library where I need. The connection string will be set in
app.configof the referencig application (or anywhere else).