f# - SqlDataProvider connection string in Suave on Azure -
i can't sqldataprovider work when executed in fsx script running in azure web site.
i have started samples tomas petrecek has here: https://github.com/tpetricek/dojo-suave-fshome.
in short fsx script executed using iis httpplatformhandler http requests azure web site forwarded f# script.
the f# script use suave handle requests.
when tried adding database access http handlers got problems.
the problematic code looks this:
[<literal>] let connstr = "server=(localdb)\\v11.0;initial catalog=my_database;integrated security=true;" [<literal>] let resolutionfolder = __source_directory__ fsharp.data.sql.common.queryevents.sqlqueryevent |> event.add (printfn "executing sql: %s") // following line fails when executing in azure type db = sqldataprovider<connstr, common.databaseprovidertypes.mssqlserver, resolutionpath = resolutionfolder> let savedata somedatatosave = let ctx = db.getdatacontext(environment.getenvironmentvariable("sqlazureconnstr_queries")) ..... /// code using context here
this works fine when run locally, when deploy azure site fail @ line type db
is created.
the error message (line 70 line has type db = ...
:
d:\home\site\wwwroot\app.fsx(70,11): error fs3033: type provider 'fsharp.data.sql.sqltypeprovider' reported error: network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: sql network interfaces, error: 52 - unable locate local database runtime installation. verify sql server express installed , local database runtime feature enabled.)
the design-time database in connstr
not available in azure site, thought why have getdatacontext
overload takes connection string used @ run-time?
is because running script , not compiled code trying access database when creating typeprovider
? if yes, mean option compile , provide database code compiled assembly load , use in suave fsx script?
reading connection string config file not work in azure site. need connection string environment variable (which set in azure management interface).
hmm, bit unfortunate - @fyodor mentioned in comments, problem script-based deployment azure compiles script on azure machine - , need have statically-resolved connection string works on azure.
there 2 options:
use compiled project instead. if compile f# code locally , deploy compiled code azure work. sadly, there no samples that.
do clever trick make connection string accessible script @ compile time.
send pr sql provider can give name of environment variable , reads connection string there.
i think (3) quite nice , useful feature.
i'm not sure best way (2) be. think might able modify app.azure.fsx
creates file (say connection.fsx
) contains like:
module connection let [<literal>] connstring = "<contents of sqlazureconnstr_queries>"
then app.fsx
load script , use connection.connstring
in argument of sql type provider.
Comments
Post a Comment