使用 Entity Framework 时出现 SQLite 错误,提示“无此列”。

3

我正在追踪一个只在一些客户机器上出现的bug,当然我们无法在公司内部复现这个错误。抛出的InnerException是:

SQLite错误:没有这样的列:Extent1.UserDefinedPid

无法找到的列是SQLite数据库中这样定义的一个位字段:

[UserDefinedPid] bit NOT NULL DEFAULT 0

EDMX文件包含以下定义(只是部分内容):
<EntityType Name="Parameter">
  <Key>
    <PropertyRef Name="ParameterID" />
  </Key>
  <Property Type="Int64" Name="ParameterID" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
  ...
  <Property Type="Boolean" Name="UserDefinedPid" Nullable="false" />
  ...
</EntityType>

我们已经确认相同的SQLite数据库文件和正确的 System.Data.SQLiteSystem.Data.SQLite.Linq dlls 被加载,但由于某些奇怪的原因,一些计算机似乎认为这个列丢失了。
我们使用的数据库是加密的,我们有一个 app.config 文件用于确保其他安装的 SQLite 不会干扰应用程序。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections></configSections>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <system.data>
    <DbProviderFactories>
      <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>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SQLite" culture="neutral" publicKeyToken="db937bc2d44ff139" />
        <bindingRedirect oldVersion="1.0.0.0 - 2.0.0.0" newVersion="1.0.66.0" />
      </dependentAssembly>
     </assemblyBinding>
  </runtime>
</configuration>

我不知道为什么这在某些机器上会失败,欢迎任何建议 :-)


列的名称是什么?是否有任何有趣的特点,例如,它是否包含重音字符? - Jon Skeet
@JonSkeet 一些机器上引发错误的列名为UserDefinedPid。除了在某些机器上失败而在其他机器上不失败之外,它并没有什么特别有趣的地方。有问题的机器运行Windows 7 Professional SP1 64位操作系统。 - Brian Wenhold
1个回答

0

我强烈怀疑您正在使用一个相当老的版本System.Data.SQLite。

也许您可以尝试一下在这里找到的最新版本。

一旦您这样做了,app.config文件将不再需要这个:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Data.SQLite" culture="neutral" publicKeyToken="db937bc2d44ff139" />
    <bindingRedirect oldVersion="1.0.0.0 - 2.0.0.0" newVersion="1.0.66.0" />
  </dependentAssembly>
 </assemblyBinding>

我对你提到的加密问题有点不清楚。你是用提供给SQLiteConnection连接对象的密码进行加密,还是使用SEE扩展


我们正在使用的版本是1.0.66.0,该版本发布于2010年4月。我们尝试在出现问题的计算机上使用最新的构建版本1.0.81.0,但它立即崩溃,并且无法打开连接(可能是加载数据提供程序时出错)。我们在数据库上使用RSA加密来保护我们的知识产权。虽然加密本身不是问题,但如果有可能会引起问题,我想确保我已经指出了这一事实。 - Brian Wenhold
@BrianWenhold:我的看法是,在进一步处理目前的问题之前,先找出新版本的问题并使用它;如果需要的话,可以开始一个新的问题。 - user610650

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接