f# - SqlDataConnection type provider - setting database connection string with script parameter -


the normal way of using sqldataconnection type provider follows:

type dbschema = sqldataconnection<"data source=myserver\instance;initialcatalog=mydatabase;integrated security=sspi;"> let db = dbschema.getdatacontext() 

however have problem want use type provider in f# script connection string database passed parameter. this:

let connectionstring= array.get args 1 type dbschema = sqldataconnection<connectionstring> 

however gives error "this not constant expression or valid custom attribute value"

is there way this?

unfortunately there's no way this, type provider requires compile time literal string. when you're compiling application, type provider's able connect , retrieve metadata database , generate types compiler. can choose extract out connection string string literal writing in form

[<literal>] let connstring = "data source=..." type dbschema = sqldataconnection<connstring> 

assuming 2 databases have same schema, it's possible supply runtime connection string parameter getdatacontext method like

let connectionstring = args.[1] let dbcontext = dbschema.getdatacontext(connectionstring) 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -