1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, simple and effective. There is also an overload that takes an open connection, which can be useful for injecting more complex scenarios (for example, using mini-profiler, which exists as an ado.net decorator)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.