3

相关问题: 在另一台机器上运行我的应用程序给我一个错误

这是我的 App.config 文件的样子:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="DocumentsDBEntities" connectionString="metadata=res://*/Documents.csdl|res://*/Documents.ssdl|res://*/Documents.msl;provider=System.Data.SQLite;provider connection string=&quot;data source=C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\DocumentsDB.sqlite&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
  <appSettings>
    <add key="Username" value="administrador"/>
    <add key="Password" value="123456"/>
  </appSettings>
</configuration>

在我的开发机器上运行它可以工作,但是在部署到另一台计算机时,我收到数据提供程序错误。(见上面的相关问题)。

建议的解决方案是将其添加到 App.config 文件中:

<system.data>
        <DbProviderFactories>
                <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>

当我将它添加到 App.config 文件时,在 Visual Studio 2010 中启动应用程序时出现此错误:

为 system.data 创建配置节处理程序时出错:列“InvariantName”被限制为唯一。值“System.Data.SQLite”已经存在。(C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\bin\Debug\DocumentScannerDanyly.vshost.exe.Config 第 13 行)

关于这个错误是什么的任何建议?此外,由于 .sqlite 文件的位置与其安装位置相关,我是否必须将 AppConfig 文件中的 connectionString 更改为更动态的内容?

谢谢您的帮助。

编辑:

当我按照此处某人的建议将其添加到配置中时,出现错误:

<system.data>
        <DbProviderFactories>
                <clear />
                <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>

未能找到或加载已注册的 .Net Framework 数据提供程序。

4

3 回答 3

11

这是因为当您安装 SqlLite 时,它​​会更新您的 machine.config:

<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>

因为您没有在安装了 SqlLite 的机器上运行,所以 DbProviderFactories 不知道 SqlLite。

在您的目标计算机上安装 SqlLite 或将其添加到您的配置中:

<system.data>
        <DbProviderFactories>
                <clear />
                <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>

这将阻止你与你的 machine.config 发生冲突,并允许它在你的目标机器上工作。如果您使用任何其他 Sql 数据提供程序,您还需要添加它。

编辑

如果 clear 不起作用,请尝试:

<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>
于 2010-11-19T14:30:14.633 回答
3

在添加上述解决方案时,我遇到了同样的问题

未能找到或加载已注册的 .Net Framework 数据提供程序。

但解决的方法是将“复制本地”设置为 true forSystem.Data.SQLite和 forSystem.Data.SQLite.Linq在参考文献中。

我希望它也能帮助你。

于 2013-03-16T11:30:43.687 回答
2

问题很可能是您在连接字符串中硬编码到桌面的路径:

C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\DocumentsDB.sql

除非此文件在另一台机器上的位置完全相同,否则它可能无法正常工作

于 2010-11-19T14:29:31.913 回答