3

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?

4
  • Can you create a minimal test case? An application as small as possible that still has the problem? Commented Feb 21, 2012 at 9:02
  • Where your connection string is defined? Commented Feb 21, 2012 at 9:02
  • @KirillPolishchuk I've created a dll project for accessing data. when i create my dbml file putting the tables i use inside it, the connection string is saved in a settings file and also in the app.config file of my "data-access-project". I'd like to specify the connection string in the project that uses as reference this dll... is it possible? Commented Feb 21, 2012 at 9:09
  • 2
    This should help you goneale.com/2009/03/26/… Commented Feb 21, 2012 at 9:14

1 Answer 1

3

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 dbml file I added in my DAO class a constructor that takes a parameter:

public MyDataAccessClass(string connectionString)
{
     _connString = connectionString;
}

then instead of using DataClasses() constructor to instantiate the LINQ-TO-SQL class, I replaced it with DataClasses(_connString).

Now I can use the data access library where I need. The connection string will be set in app.config of the referencig application (or anywhere else).

Sign up to request clarification or add additional context in comments.

1 Comment

The page you linked is no longer available. Could you put a summary of what it said in your answer please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.