SQLite错误:' DbProviderFactories'每个配置文件中该部分只能出现一次(IBM Client Access) [英] SQLite Error: The 'DbProviderFactories' section can only appear once per config file (IBM Client Access)

查看:82
本文介绍了SQLite错误:' DbProviderFactories'每个配置文件中该部分只能出现一次(IBM Client Access)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.NET 4.5上使用WPF和C#为我的应用程序使用Entity Framework和System.Data.SQLite在我的机器上可以正常工作,但是在测试机器上,当我通过EntityFramework访问sqlite db时收到此错误:

I'm using for my application Entity Framework and System.Data.SQLite using WPF and C# on .NET 4.5 On my machine al work well, but on a test machine a received this error when I access to the sqlite db via EntityFramework:

"DbProviderFactories"部分在每个配置中只能出现一次文件.

The 'DbProviderFactories' section can only appear once per config file.

我发现错误是在测试机器中的machine.config中出现的:

I found that the error was that in the test machine, in the machine.config:

<system.data>
    <DbProviderFactories>
        <add name="IBM DB2 for i5/OS .NET Provider" invariant="IBM.Data.DB2.iSeries" description=".NET Framework Data Provider for i5/OS" type="IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26"/>
        <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
        <add name="IBM DB2 for i .NET Provider" invariant="IBM.Data.DB2.iSeries" description=".NET Framework Data Provider for IBM i" type="IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26" />
    </DbProviderFactories>
    <!-- This is the line to remove - empty element --> 
    <DbProviderFactories/>
</system.data>

我删除了最后一个空元素,现在一切正常.我认为这与IBM.Data.DB2.iSeries安装(IBM Client Access)有关.

I remove the last empty element and now all work. I think it's something related the IBM.Data.DB2.iSeries installation (IBM Client Access).

我的问题是:如何删除空元素而无需手动编辑machine.config ?我试图将标签< clear/> 插入app.config文件中,但不起作用.

My question is: How to remove the empty element without manually edit machine.config? I have tried to insert the tag <clear /> in the app.config file but not work.

我发现了另一个与我的问题类似的问题,但是没有人提出如何解决该问题的方法,而无需手动编辑machine.config来解决问题.

I found another question similar to mine but not one suggest how to solve the problem without edit manually the machine.config to solve the problem.

这是我的app.config文件:

this is my app.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.xml.serialization>
    <xmlSerializer useLegacySerializerGeneration="true" />
  </system.xml.serialization>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    <!--STAI MOLTO ATTENTO-->
    <legacyUnhandledExceptionPolicy enabled="1"/>
  </startup>
  <connectionStrings>
    <add name="db" connectionString="Data Source=clients.db;Version=3;New=False;Compress=True;" />
    <add name="icmdbEntities" connectionString="metadata=res://*/MainModel.csdl|res://*/MainModel.ssdl|res://*/MainModel.msl;provider=System.Data.SQLite;provider connection string=&quot;data source=.\icmdb.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <clear />
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
  <appSettings>
    <add key="ditta" value="default" />
    <add key="demo" value="true"/>
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

推荐答案

问题是由安装Windows的IBM iAccess引起的-特别是.NET Provider for DB2组件.我已经在V7R1中亲眼看到了它,但是其他人也提到了V6R1中的相同问题.

The problem is caused by installing IBM iAccess for Windows -- specifically the .NET Provider for DB2 component. I've seen it firsthand in V7R1, but others have referenced the same issue with V6R1.

IBM意识到了这个问题,并在其中一个服务版本中进行了修复.

IBM is aware of the problem and has a fix in one of the service releases.

从V7R1 服务发布文档:

对APAR SE45767修复的问题的描述:

在未知情况下,安装.Net数据提供程序时(作为完全安装或自定义安装类型的一部分)会损坏machine.config XML文件.损坏被隔离到与DbProviderFactories相关的XML数据的某些部分,并且通常观察到该损坏包括XML数据的某些行的重复.

DESCRIPTION OF PROBLEM FIXED FOR APAR SE45767 :

Under unknown circumstances, corruption to the machine.config XML file is occurring when the .Net data provider is installed (either as part of a Complete or Custom install type). The corruption is isolated to portions of the XML data related to the DbProviderFactories - and generally has been observed to include duplication of some lines of the XML data.

将提供预防性修复程序,以消除造成machine.config损坏的可能原因.

A preventive fix will be provided which will eliminate the likely cause of the machine.config corruption.

将不提供纠正已损坏的machine.config文件的纠正性修补程序.如果可能,请使用记录在案的本地修补程序或规避措施.

A corrective fix to update already corrupted machine.config files will not be provided. Utilize the documented local fix or circumvention if possible.

如果不需要.Net数据提供程序,则可以通过执行自定义安装并确保不会安装.Net数据提供程序来避免此问题.如果需要.Net提供程序,则没有已知的规避措施.利用本地修补程序解决此问题.

If the .Net data provider is not needed, this problem may be avoided by performing a custom install and ensuring the .Net Data provider will not be installed. If the .Net provider is required, no circumvention is known. Utilize the local fix to resolve the issue.

至于解决该问题后,您需要修复machine.config (32位和64位),因为它不符合为系统定义的架构.数据.这很容易-只需编写一个简单的.NET应用程序即可,该应用程序使用XmlDocument加载machine.config,找到重复的DbProviderFactories元素,将其删除并保存文件.或使用PowerShell脚本或其他任何可以处理XML文档的东西.

As for fixing the problem once it has occurred, you need to fix machine.config (both 32-bit and 64-bit), because it does not conform to the schema defined for system.data. That's easy -- just write a simple .NET app that uses XmlDocument to load machine.config, locate the duplicate DbProviderFactories element, delete it and save the file. Or use a PowerShell script or anything else that can manipulate XML documents.

这是一个 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆