Sql F#Type Provider,App.Config和ConnectionStrings?

时间:2015-02-08 12:20:48

标签: sql f# type-providers

我正在尝试使用app.config文件将连接字符串加载到类型提供程序中,但是我收到以下错误:

  

错误FS3033:类型提供程序'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders'报告错误:配置文件''中连接字符串条目'Server1'中的提供程序'...\app.config'无效。 SqlDataConnection只能与提供商'System.Data.SqlClient'一起使用。

我将连接字符串放在app.config文件中,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="..." culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="Server1" connectionString="Server=..."/>
    <add name="Server2" connectionString="Server=..."/>
  </connectionStrings>
</configuration>

然后在F#中引用它们:

type dbSchema = SqlDataConnection<ConnectionStringName = "Server1", Views = false, Functions = false, StoredProcedures = false>

问题出在哪里?

1 个答案:

答案 0 :(得分:0)

请提供providerName连接字符串。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="..." culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="Server1" connectionString="Server=..." providerName="System.Data.SqlClient"/>
    <add name="Server2" connectionString="Server=..."/>
  </connectionStrings>
</configuration>

我已调整提供的app.configServer1功能,Server2因您报告的消息而失败。