将配置添加到App.config文件时出错 [英] Error when adding a configuration to App.config file

查看:1628
本文介绍了将配置添加到App.config文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

This is how my App.config file looks like:

<?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>

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

Running this on my dev machine works, but when deploying to another computer, I get an Data Provider error. (see related question above).

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

The suggested solution was to add this to the App.config file:

<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:

When I add that to the App.config file, I get this error when launching the application in Visual Studio 2010:



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

An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique. Value 'System.Data.SQLite' is already present. (C:\Users\Sergio.Tapia\Desktop\DocumentScannerDanyly\DocumentScannerDanyly\bin\Debug\DocumentScannerDanyly.vshost.exe.Config line 13)

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

Any suggestion on what this error is? Also, since the location of the .sqlite file is relative to where it is installed, do I have to change the connectionString in the AppConfig file to something more dynamic?

谢谢帮助。

编辑:

当我将其添加到配置根据某人的建议,我收到一个错误:

When I add this to the config as suggested by someone here, I get an error:

<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数据提供程序。

Failed to find or load the registered .Net Framework Data Provider.


推荐答案

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

The problem is most likely that you hard code a path to your desktop in your connection string:

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

除非该文件与另一台机器上的完全相同的位置存在,否则有可能不能工作

Unless this file is present with the exact same location on the other machine, chances iare it won't work

这篇关于将配置添加到App.config文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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