提供到Linq-To-Sql数据提供程序的连接字符串 [英] Providing connection string to Linq-To-Sql data provider
本文介绍了提供到Linq-To-Sql数据提供程序的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以从App.Config文件中以F#提供到Linq-To-Sql数据提供程序的连接字符串.
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"
谢谢
推荐答案
类型提供程序本身需要一个硬编码的连接字符串来生成要在编译时进行开发的类型(在您的情况下为SqlConnection
),但是,可以这样配置运行时使用的实际连接字符串:
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)
这篇关于提供到Linq-To-Sql数据提供程序的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文