wf Khani
wf Khani

Reputation: 1165

How Force Linq to Sql classes to use connection string from file

I want to put my connection string in a file like .udl, to change connection string from outside project, because i want to put my db to a server.

I use LINQ to SQL Classes and typed dataset, i want those items use a connection string inside a file near the project(like udl), could i do that?

Upvotes: 1

Views: 408

Answers (1)

Kirill Shlenskiy
Kirill Shlenskiy

Reputation: 9587

LINQ to SQL DataContext has a constructor which accepts a connection string. That connection string is passed on to the provider (see http://msdn.microsoft.com/en-us/library/bb350721.aspx).

You could read the connection string from an arbitrary file and pass it to said constructor when you need to initialize your DataContext object.

Upvotes: 2

Related Questions