Asp.net MVC连接数据库mdf文件
问题描述:
你好,
我在SQL服务器上有数据库的小型asp.net mvc项目。我需要在面试时提出,所以我需要通过电子邮件发送。我需要知道什么是最好的方法,如何将mdf文件导出并连接到项目,以便数据库始终绑定到项目文件夹。你能给我一些提示吗?
我尝试过的事情:
我正在考虑将mdf文件复制到项目并更改连接字符串
Hello,
I have small asp.net mvc project with database on SQL server. I need to present it at the job interview so I need to send it via email. What I need to know what is the best way, how to export and connect the mdf file to the project so the database is always tied to the project folder. Can you give me any tips please?
What I have tried:
I was thinking about just copy mdf file to project and change the connection string
答
嗨Jakub,
我建议数据库文件的最佳实践如下:
1.导出脚本 - 您可以将数据作为脚本文件导出SQL Server数据库脚本。然后,你可以创建一个新的数据库并运行它脚本文件,而你想要它。
(或)
2.项目文件夹里面 - 您可以将SQL Server数据库文件(.MDF)保存在项目文件夹内的App_Data文件夹中。然后,您可以使用SQL Server Management Studio附加数据库文件(.MDF),而您可以使用它。您可以在项目中使用数据库连接字符串。
如果您需要帮助,请告诉我
Hi Jakub,
I recommend best practice for database file as the following
1. Export the Script - you can export the SQL server database script with data as the script file. Then, you can create a new database and run it the script file whereas you want it.
(or)
2. Project folder inside - you can keep the SQL server database file (.MDF) on the App_Data folder inside the project folder. then you can attach the database file (.MDF) using SQL Server Management Studio whereas you want it. you can use the database connection string in your project.
Please let me know if you want any help