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
  • 62,044
  • 9
  • 127
  • 211
fitims
  • 323
  • 1
  • 4
  • 10

3 Answers3

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)
Stephen Swensen
  • 22,107
  • 9
  • 81
  • 136
3

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

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

Jizugu
  • 790
  • 1
  • 7
  • 13
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

Community
  • 1
  • 1
Quintus Marais
  • 810
  • 9
  • 15