0

I need write simple util, which will connect to different databases. It'll be good to use LINQ. How can I create custom connection using LINQ? For example, there'll be form with 4 textboxes: server, database name, login and password. And I need create connection string with this params.

I know how can I do it via ADO, but I need use LINQ.

P.S. LINQ to SQL.

Jim Wooley
  • 10,169
  • 1
  • 25
  • 43
Max Zhukov
  • 877
  • 1
  • 8
  • 32

2 Answers2

0

You can use the SqlConnectionStringBuilder to build a connection string from your inputs and then pass that to the constructor of your DataContext.

Jim Wooley
  • 10,169
  • 1
  • 25
  • 43
0

The SqlConnectionStringBuilder performs checks for valid key/value pairs. Therefore, you cannot use this class to create invalid connection strings; trying to add invalid pairs will throw an exception. The class maintains a fixed collection of synonyms and can translate from a synonym to the corresponding well-known key name.

Kumar Manish
  • 3,746
  • 3
  • 37
  • 42