locked
Feature Request - LINQ to SQL On Connecting event for the Data Context RRS feed

  • Question

  • Hi

    I love LINQ to SQL. There is only one thing I would really like added. An OnConnecting event in the Datacontext. This would help apps that need to switch databases at runtime to have one and only one place to specify the switch for all code the uses the datacontext. Does any one know how this can be achieved with the current LINQ to SQL

    Thanks

    Tuesday, August 27, 2013 9:43 AM

Answers

  • When you create the DataContext there is an overload that takes a connection string which it will use without modifying it. Therefore you can connect to any server that host the database of which the model in your application is using.

    MyDataContext context = new MyDataContext( MyConnectionString );

    See documentation DataContext Constructor (String)

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, August 28, 2013 4:05 AM