使用MVC5将LocalDB切换到SQL Server数据库 [英] Switch LocalDB to SQL server db with MVC5
问题描述
我已经在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 :
按照所有简单的步骤将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"命令
这是官方指南:
从工具"菜单中,选择"NuGet程序包管理器">程序包管理器控制台".在PM>提示符下,输入以下命令:
- 启用迁移
- 添加迁移InitialCreate
- 更新数据库
数据库将在迁移期间自动创建.如果已经有一个,请确保备份所有表.
The database will be created automatically during migration. If you already have one make sure to backup all tables.
这篇关于使用MVC5将LocalDB切换到SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!