简体   繁体   English

我的 MVC 应用程序无法识别数据库连接

[英]My MVC application couldn't recognize the database connection

In my mvc application, everything was working fine before but when i made some changes (the database name, user id & password) in the Connection string in the App.Config, my application is not recognizing anymore the database connection.在我的 mvc 应用程序中,之前一切正常,但是当我在 App.Config 的连接字符串中进行一些更改(数据库名称、用户 ID 和密码)时,我的应用程序不再识别数据库连接。

<!-- DEVELOPPEMENT ORIOLIS -->
<add name="DEAXIMAEntities" connectionString="metadata=res://*/DeAximaDataModel.csdl|res://*/DeAximaDataModel.ssdl|res://*/DeAximaDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\SQLEXPRESS;initial catalog=AXIMADB;persist security info=True;user id=****;password=****;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

it shows me the error like this everywhere i'm using my database connnection variable它在我使用数据库连接变量的任何地方都向我显示这样的错误

using System.Web.Mvc;
using DAL;
using System;
using MvcAppDE.Fonctions;
using MvcAppDE.Filters;

namespace MvcAppDE.Controllers
{
    [IsRegisteredUser]
    public class HomeController : Commun.BaseController
    {
//it doesn't recognize anymore this database connection variable
        private DEAXIMAEntities db = new DEAXIMAEntities(); 
        private readonly string user = Environment.UserName;
        private string GetTitre() => "Bonjour " + db.UTILISATEUR.Find(user).UTILISATEUR_PRENOM;
       // private int dmCount = BaO.DemandesCount();
        private readonly int dmECCount = BaO.DemandesECCount();
    }
}

数据库连接变量截图

so i ended up getting this same error where it says CS0246 C# The type or namespace name could not be found (are you missing a using directive or an assembly reference?)所以我最终得到了同样的错误,它说CS0246 C# 找不到类型或命名空间名称(您是否缺少 using 指令或程序集引用?)错误列表截图

I've been trying to find the answer by looking at all the related questions on this forum but i haven't found the suitable solution yet.我一直试图通过查看这个论坛上的所有相关问题来找到答案,但我还没有找到合适的解决方案。

PS: I'm a beginner in mvc asp .net so couldn't really figure it out by myself. PS:我是 mvc asp .net 的初学者,所以我自己无法弄清楚。 thanks for your help in advance!提前感谢您的帮助!

1.Go to Edmx file 1.Go 到 Edmx 文件

2.expand edmx file & select.context.cs file -- double click 2.展开edmx文件&select.context.cs文件——双击

namespace DeAximaDataModel { 
  public partial class DEAXIMAEntities  : DbContext {
    public DEAXIMAEntities () : base("name=DEAXIMAEntities") // this name only u should give in controllers
    {

    } 
  } 
}

Just for the people looking for the answer in the future!只为那些在未来寻找答案的人!

when i was remodifying the App.config in my application, i don't know why but the visual studio had emptied the.context.cs file(found it after expanding the.EDMX file) whhich made my database connection unfoundable.当我在我的应用程序中重新修改 App.config 时,我不知道为什么,但 Visual Studio 清空了 .context.cs 文件(在扩展 .EDMX 文件后找到它),这使我的数据库连接无法找到。 I somehow recovered all the code from the backup folder and pasted it in the same file.我以某种方式从备份文件夹中恢复了所有代码并将其粘贴到同一个文件中。 so that it can finally work again without any errors.以便它最终可以再次正常工作而不会出现任何错误。

thanks to all who helped me understand the problem and the concerned area in the project.感谢所有帮助我了解项目中的问题和相关领域的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM