简体   繁体   English

ASP.NET MVC中App_Data文件夹下缺少.mdf文件

[英].mdf file missing under the App_Data folder in ASP.NET MVC

I was following the tutorial on creating the Code First Entity Framework model on Asp.NET MVC Application from this tutorial . 我正在遵循本教程中有关在Asp.NET MVC应用程序上创建代码优先实体框架模型的教程

As I proceeded, a file with the .mdf extension should have been generated under the App_Data folder in my project (in the solution explorer section). 在继续进行操作时,应该已经在我的项目(在解决方案资源管理器部分中)的App_Data文件夹下生成了扩展名为.mdf的文件。 Currently this folder is empty. 当前此文件夹为空。

I have tried building the project and cleaning it. 我尝试过构建该项目并对其进行清理。 Moreover I have enabled Show All Files option in the folder. 此外,我在文件夹中启用了“ 显示所有文件”选项。 I even did a refresh. 我什至做了刷新。 The Entity Framework works just fine and is able to connect and retrieve from the database. 实体框架工作正常,并且能够连接数据库并从数据库中检索。 However the App_Data folder is empty. 但是,App_Data文件夹为空。

Here is are my connection strings: 这是我的连接字符串:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-UsingEntityFramework-20161002112829.mdf;Initial Catalog=aspnet-UsingEntityFramework-20161002112829;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="MovieDBContext" connectionString="Data Source=tcp:xxxxxxxxxx.net;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxxx;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Check your web.config and notice the connectionString and see the data source, maybe it is creating it under your SQL Server not inside the App_Data 检查您的web.config并注意connectionString并查看数据源,也许它是在您的SQL Server下而不是App_Data内创建的

The MDF File will be created when the database is created, and since this is a code first, the database will not be created unless you run the application and start connecting to the database, EF will create the database if it doesn't exist and will compare the schema to the schema in the Migrations folder and it will update the database if it is not up to date. 创建数据库时将创建MDF文件,并且由于这是首先代码,因此除非您运行应用程序并开始连接数据库,否则不会创建数据库,EF将创建数据库(如果数据库不存在),并且会将架构与“迁移”文件夹中的架构进行比较,如果数据库不是最新的,它将更新数据库。

You can also open Nu Get Package Manager and run the command Update-Database to create and update the database. 您也可以打开Nu Get软件包管理器并运行命令Update-Database来创建和更新数据库。

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

相关问题 ASP.NET 项目未在 app_data 中创建 .mdf 文件 - ASP.NET project not creating .mdf file in app_data 如何让 Visual Studio 使用我的数据库,而不是位于 ASP.NET MVC 项目的 App_Data 文件夹中的 .mdf 文件? - How can I make Visual Studio use my database instead of the .mdf file located in App_Data folder in ASP.NET MVC project? 想要在实时服务器中上传文件,而不是ASP.Net MVC中的App_Data文件夹 - Want to upload file in the live server other than App_Data folder in ASP.Net MVC 缺少ASP.NET MVC .mdf文件 - ASP.NET MVC .mdf file missing 如何将数据写入ASP.NET MVC中的App_Data文件夹? - How can I write data to the App_Data folder in ASP.NET MVC? 如何允许仅在App_Data asp.net mvc中下载访问特定文件夹 - how to allow download access to specific folder only in App_Data asp.net mvc 如何删除“ / App_Data / uploads”文件夹中的上载文件ASP.NET MVC - How to delete the uploaded files in the “/App_Data/uploads” folder ASP.NET MVC ASP.Net vNext App_Data文件夹 - ASP.Net vNext App_Data folder ASP.NET MVC 4拒绝访问路径App_Data - ASP.NET MVC 4 Access to the path App_Data is denied 为什么 mdf 文件没有出现在 App_Data 文件夹中? - Why is mdf file not appearing in the App_Data folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM