8

Is there a way to provide a connection string to Linq-To-Sql data provider in F# from App.Config file.

I have tried the following just for testing:

let mutable connString = @"Data Source=PCSQLEXPRESS;Initial Catalog=NortwindDB;Integrated Security=True"
type SqlConnection = SqlDataConnection<ConnectionString = connString>

but I get an error message "This is not a constant expression or valid custom attribute value"

Thanks

ildjarn
63.2k9 gold badges133 silver badges219 bronze badges
asked May 9, 2012 at 22:00

3 Answers 3

14

The type provider itself requires a hard-coded connection string for generating the type (in your case SqlConnection) to develop against at compile time, but, you can configure the actual connection string used at runtime like so:

type SqlConnection = SqlDataConnection<"Data Source=PCSQLEXPRESS;Initial Catalog=NortwindDB;Integrated Security=True">
let runtimeConnStr = ...
type dataContext = SqlConnection.GetDataContext(runtimeConnStr)
answered May 10, 2012 at 12:49
3

Maybe using the "?ConnectionStringName" parameter will get you where you want.

http://msdn.microsoft.com/en-us/library/hh362320(v=VS.110).aspx

answered May 23, 2012 at 21:23
0

You might also want to look at the following question which has a solution for this in answers F# Type Providers and Continuous Integration

answered Oct 29, 2013 at 11:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.