views:

192

answers:

3

Hey Guys. This question may be redundant, but i could not totally understand how to do this. I need to be able to, when the users Run my Winforms app, can search for the instance of SQL if the previous one are not available. I already have the check for the DB existence, and also made a dialog wich search for all the available instance, and bulding the connection string isn't a problem. The point here is that, I need to be able to everytime the users open the app it loads the CN from a external file, and if the external file doesn't exist or the instance isn't available, i can use the app in another instance (asuming, offcourse, that the required DB is in that Instance). The point is that, i don't know how to Programmatically change Connection String, using LINQ in winforms. Thanks in advance

+3  A: 

You should be to pass the connection string to the DataContext constructor.

var db = new MyDataContext(myconnectionstring);
ichiban
Thanks... didn't know, but now i DO!First one get the answer check
josecortesp
+1  A: 
var someConnectionString = "This is my connection String";

using (var db = new SomeConcreteDataContext(someConnectionString)){
    //...Do whatever...
}
Jason Punyon
A: 

A DataContext is created per 'unit of work'.

As ichiban says pass the required connection string into the constructor when creating the DC

Dve