简体   繁体   English

asp.net mvc从.mdf文件加载数据库

[英]asp.net mvc Load Database from .mdf file

I'm building an Web App using MVC, using Entity Framework. 我正在使用实体框架使用MVC构建Web应用程序。 Usually, the entity framework takes data from the database from the MSSQL server installed on machine. 通常,实体框架从安装在计算机上的MSSQL服务器获取数据库中的数据。

I want to make at login a check, for example, if the connection at database is ok, if not, to take a .mdf file (stored on a cloud server) and use the data from that db. 我想在登录时进行检查,例如,如果数据库中的连接正常,如果没有,则获取.mdf文件(存储在云服务器上)并使用该数据库中的数据。

This will be the 'emergency' database, backup etc. 这将是“紧急”数据库,备份等。

Is this possible? 这可能吗?

You can use DbContext constructor that takes connection string to the database. 您可以使用DbContext构造函数将连接字符串作为数据库。 That's how you can handle to which DB you will connect. 这就是你如何处理你将连接的数据库。

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

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