问题描述
我在Visual Studio 2013(用于Web的Express)中创建了一个新的ASP.NET MVC 5项目,默认情况下,该项目使用LocalDb作为其数据库,但是如何将数据库传输或迁移到SQL Server?
I created a new ASP.NET MVC 5 project in Visual Studio 2013 (Express for Web) and by default, the project uses LocalDb as its database, but how do you transfer or migrate the database to SQL Server?
我想对数据库使用SQL Server而不是LocalDb.但是如何?
I want to use SQL Server for the database instead of LocalDb. But how?
推荐答案
知道了!
基于@ warheat1990的答案,您只需更改连接字符串.但是@ warheat1990的答案有太多变化.这是我原始的(LocalDb)连接字符串:
Based on @warheat1990's answer, you just have to change the connection string. But @warheat1990's answer had a little too much change. So here's my original (LocalDb) connection string:
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-my_project-20150318100658.mdf;Initial Catalog=my_project-20150318100658;Integrated Security=True"
providerName="System.Data.SqlClient"/>
要将其连接到SQL Server而不是LocalDB,我将连接字符串修改为:
To connect it to SQL Server instead of LocalDB, I modified the connection string into:
<add name="DefaultConnection"
connectionString="Data Source=SERVERNAME\SQLEXPRESS;Initial Catalog=my_project;Integrated Security=True"
providerName="System.Data.SqlClient"/>
感谢@ warheat1990提出了简单更改Web.config的想法.我的第一个想法是确定并使用VS提供的功能(如果有的话).因为Microsoft没有有关如何执行此操作的简明文档.
这篇关于如何将ASP.NET MVC数据库从LocalDb传输到SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!