开发者

How do I Programmatically change Connection String un LINQ C# Winforms

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 instanc开发者_如何学Ce, 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


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

var db = new MyDataContext(myconnectionstring);


var someConnectionString = "This is my connection String";

using (var db = new SomeConcreteDataContext(someConnectionString)){
    //...Do whatever...
}


A DataContext is created per 'unit of work'.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜