配置web.config以使用sql server数据库的问题

时间:2014-02-12 19:49:49

标签: web-config breeze hottowel

我在玩John Papa的HotTowel应用程序。 HotTowel示例使用本地codecamper.sdf数据库,我试图将其配置为在sql server 2008 r2上使用数据库。当我运行该应用程序时,我收到一条错误消息“Breeze.ContextProvider.EF6.dll中发生类型'System.InvalidOperationException'的异常,但未在用户代码中处理。”错误发生在显示“get {return _contextProvider.Metadata()”代码的行上的CodeCamperRepository.cs中。内部例外说

The connection string 'CodeCamper' in the application's configuration file does not contain the required providerName attribute." 

我在web.config中有以下代码,但我不确定它是否正确:

<configuration>
      <configSections>
            <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
       </configSections>
       <connectionStrings>
          <add name="CodeCamper" connectionString="Data Source=testdb\cmstest; Integrated Security=True; MultipleActiveResultSets=True" />
      </connectionStrings>
      <system.web>
          <compilation debug="true" targetFramework="4.5" />
          <httpRuntime targetFramework="4.5" />
      </system.web>
      <entityFramework>
          <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
            <parameters>
               <parameter value="Data Source=testdb\cmstest; Integrated Security=True; MultipleActiveResultSets=True" />
            </parameters>
        </defaultConnectionFactory>
          <providers>
             <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
        </entityFramework>
        <system.webServer>
          <handlers>
              <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
              <remove name="OPTIONSVerbHandler" />
              <remove name="TRACEVerbHandler" />
              <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
          </handlers>
        </system.webServer>
      </configuration>

我应该考虑使HotTowel连接到Sql Server吗?什么是微风不喜欢配置?欣赏任何见解。

感谢社区 NP

2 个答案:

答案 0 :(得分:2)

就像内部异常所说:你需要providerName属性。因此,将ConnectionStrings部分更改为:

<connectionStrings>
    <add name="CodeCamper" connectionString="Data Source=testdb\cmstest; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

答案 1 :(得分:0)

只是检查,但你的DbContext构造函数中是否有CodeCamper连接引用?

public CCDbContext()
        : base("CodeCamper"){ }