重复的连接字符串错误 [英] Duplicate Connection String Error

查看:97
本文介绍了重复的连接字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有部署在服务器中的网页。有一天,它抛出一个错误说名称已经添加了连接字符串。我检查了web.config文件,并在该名称只有一个条目。我删除从配置项。现在,该网站运作良好,并从数据库中读取数据。

请注意:当我改变配置文件的名称,它显示误差

我想,这个问题是 - ConnectionString中部分被缓存在内存中。是这样吗?我们怎样才能克服这种不必要的行为?

配置文件中源$ C ​​$ C

发布配置

 <&的System.Web GT;
 <编译XDT:转换=RemoveAttributes(调试)/>< /system.web>

调试配置

 <&的System.Web GT;< /system.web>

参考文献:


  1. Issue与不必要的连接字符串中我发表的web配置
  2. 出现
  3. .NET 2.0 App.Config中的连接字符串包含多余的SQLEx preSS默认


解决方案

这不是问题 - 当你修改的web.config 文件时,IIS进程得到复位,所以不能有任何缓存参与。

什么是更可能的是,有两种与包含的相同的连接字符串名称的web.config 文件中的父母或子女目录 - 这是导致错误

您可以解决在几个方面:


  • 确保只有一个的web.config 与连接字符串名称
  • 正确的范围
  • 使用删除元素:

     <&是connectionStrings GT;
     <清除NAME =theConnectionString/>
     <添加名称=theConnectionString... />
    <&是connectionStrings GT;


请参照<一个href=\"http://stackoverflow.com/questions/16547034/encrypted-config-file-does-not-apply-remove-tag-in-connectionstrings\">Encrypted配置文件不适用删除了一个相关的问题的是connectionStrings标记

I have a website deployed in a server. One day it threw an error saying the connection string name is already added. I checked the web.config file and it has only one entry in that name. I removed the entry from the config. Now the website worked well and fetched data from database.

Note: When I changed the name of the config file it show error.

I think, the issue is – the connectionstring part is cached in memory. Is it so? How can we overcome this unwanted behavior?

Config Files in Source Code

Release Config

<system.web>
 <compilation xdt:Transform="RemoveAttributes(debug)" />

</system.web>

Debug Config

<system.web>

</system.web>

REFERENCES:

  1. Issue with unwanted connection string appearing in my published web config
  2. .NET 2.0 App.Config connection strings includes unwanted SQLExpress default

解决方案

That is not the issue - when you change the web.config file, the IIS process gets reset, so there can't be any caching involved.

What is more probable is that there is either a parent or child directory with a web.config file that contains the same connection string name - this is causing the error.

You can solve that in several ways:

  • Ensure there is only one web.config in the correct scope with the connection string name
  • Use the remove element:

    <connectionStrings>
     <remove name="theConnectionString" />
     <add name="theConnectionString" ... />
    <connectionStrings>
    

Refer Encrypted config file does not apply "remove" tag in connectionStrings for a related question

这篇关于重复的连接字符串错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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