使用MVC5将LocalDB切换到SQL Server数据库 [英] Switch LocalDB to SQL server db with MVC5

查看:89
本文介绍了使用MVC5将LocalDB切换到SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在MVC5下通过个人身份验证创建了一个新项目.然后,我将其构建并注册一个测试用户以测试登录系统.我已经将数据库表LocalDB迁移到了SQL Server.

I have created new project under MVC5 with individual authentication. Then I have build it and register a test user to test login system. I already migrated my database table LocalDB to my SQL server.

现在创建了用于连接SQL Server的连接字符串,但问题是它仍然使用我的旧LocalDB来将数据保存到App_Data文件夹中.

Now created connection string to connect SQL server but the problem is it is still using my old LocalDB which saving data to App_Data folder.

您能给我一些建议,将此LocalDB切换到我的SQL服务器吗?我已经创建了"ADO.NET实体数据模型",但是如何将其与SQL Server连接?任何想法?欢迎提问.

Can you give me some advice to switch this LocalDB to my SQL server? I already created "ADO.NET Entity Data Model" but how to connect it with my SQL server? Any idea? Any question welcome.

推荐答案

本指南对我来说非常有用:

This Guide was very useful for me :

https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa模板/

按照所有简单的步骤将LocalDB表移动到SQL Server数据库表.

Follow all the easy steps for move your LocalDB table to SQL server db Table.

1.检查Web.config文件连接字符串并连接到本地数据库

更改默认连接字符串:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApp-20190226025646.mdf;Initial Catalog=aspnet-WebApp-20190226025646;Integrated Security=True" providerName="System.Data.SqlClient" />

连接字符串:

<add name="DefaultConnection" connectionString="Data Source=PC-YWGSB;Initial Catalog=WebApp;user id=admin;password=admin" providerName="System.Data.SqlClient" />

2.然后使用数据库迁移"Codefirst"命令

这是官方指南:

> https://docs.microsoft.com/it-it/aspnet/mvc/overview/getting-started/在asp-net-mvc应用程序中开始使用ef-using-mvc/migrations-and-deployment与实体框架

从工具"菜单中,选择"NuGet程序包管理器">程序包管理器控制台".在PM>提示符下,输入以下命令:

  1. 启用迁移
  2. 添加迁移InitialCreate
  3. 更新数据库

数据库将在迁移期间自动创建.如果已经有一个,请确保备份所有表.

The database will be created automatically during migration. If you already have one make sure to backup all tables.

这篇关于使用MVC5将LocalDB切换到SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆