简体   繁体   English

从本地数据库更改为 SQL 服务器托管在服务器上

[英]Changing from local database to SQL Server hosted on a server

So I'm fairly new to MVC and C# in Visual Studio.所以我对 Visual Studio 中的 MVC 和 C# 相当陌生。 I recently completed the tutorial located at:我最近完成了位于以下位置的教程:

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-应用

It was fun and educational in some aspects.这在某些方面很有趣,也很有教育意义。 I have one question though about the database it connects to, in the tutorial it creates a local SQL Server database and the CRUD then works off that.我有一个关于它连接到的数据库的问题,在教程中它创建了一个本地 SQL 服务器数据库,然后 CRUD 可以解决这个问题。 I currently have an external SQL Server database hosted on a server that I would like to be able to play with, I have successfully connected to it through Visual Studio (2012) but was wondering how hard it is to transfer the CRUD over to it.我目前有一个外部 SQL 服务器数据库托管在我希望能够使用的服务器上,我已通过 Visual Studio (2012) 成功连接到它,但想知道将 CRUD 转移到它有多难。

After reading up a little bit I altered the connection string, and added:在阅读了一点之后,我更改了连接字符串,并添加了:

using System.Data.SqlClient

But I am still using:但我仍在使用:

using System.Data.Entity

Unsure if I need both, and I am ofc using EF (Entity Framework).不确定我是否需要两者,并且我正在使用 EF(实体框架)。

Can anyone advise what other steps would need to be done in order to successfully transfer this over?谁能建议需要完成哪些其他步骤才能成功转移? Or in what direction I should look because tbh I am not a database or SQL expert (or MVC) and it gets a bit confusing.或者我应该朝哪个方向看,因为我不是数据库或 SQL 专家(或 MVC),这有点令人困惑。

Any helps, links or tutorial locations would be greatly appreciated.任何帮助、链接或教程位置将不胜感激。

Now that you are looking at the right place. 现在你正在寻找合适的地方。 You need to load the schema and data to it. 您需要将架构和数据加载到它。 Schema being the tables and relations that you have set up and the data being all the information you have already gathered and entered. 模式是您设置的表和关系,数据是您已经收集和输入的所有信息。 I use Web Deploy to do this. 我使用Web Deploy来执行此操作。 Below on some links to help you with this. 以下是一些帮助您解决此问题的链接。 If you are in visual studio. 如果你在视觉工作室。 Go to the Project Menu Package Publish settings. 转到“项目菜单包发布”设置。 Then click on Package/Publish SQL. 然后单击Package / Publish SQL。 Look at the settings in there and look at the image and links below and you should get it. 看看那里的设置,看下面的图像和链接,你应该得到它。 Let me know if this helps. 如果这有帮助,请告诉我。

Web发布工具栏

Great Web Deploy Explanation 伟大的Web部署说明

I would create a .sqlproj from the LocadDB version, then publish that to your SQL Server. 我将从LocadDB版本创建一个.sqlproj,然后将其发布到您的SQL Server。 Change the connection string in your MVC project, and you should be good to go. 更改MVC项目中的连接字符串,你应该好好去。 Note that your data won't follow. 请注意,您的数据不会跟随。

I worked with webforms but i believe it is the same you will need to edit the Connection string in the web.config file in your solution to point at the hosted DB in order to play with it. 我使用webforms但我相信你需要在解决方案的web.config文件中编辑Connection字符串,以指向托管数据库以便使用它。

SQL Server: SQL Server:

Data Source={SERVER NAME};Initial Catalog={DataBaseName};User Id={SQLUsername};Password={SQLPassword};

MySQL: MySQL的:

Server={SERVER NAME};Database={DataBaseName};Uid={SQLUsername};Pwd={SQLPassword};

Let me know if this helps. 如果这有帮助,请告诉我。

Authentication: SQL Server Authentication认证:SQL 服务器认证

在此处输入图像描述

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

相关问题 从SQL Server更改为Oracle数据库 - Changing from SQL Server to Oracle database 使用SQL Server的本地数据库 - local database using SQL Server 没有sql server的本地数据库 - Local database without sql server 如何从桌面应用程序中Web服务器上托管的SQL Server数据库中检索数据? - How I Retrieve Data from SQL Server Database hosted on a Web Server in my desktop application? 如何使用Windows Phone 8连接到服务器上已托管的SQL Server数据库 - How to connect to a SQL Server database already hosted on server with windows phone 8 如何将数据从本地SQL Server数据库更新到联机SQL Server数据库? - How to update data from local SQL Server database to online SQL Server database? 无法使用SQL身份验证从IIS托管应用程序连接到SQL Server数据库 - Unable to connect to SQL Server database from IIS hosted application using SQL authentication 从 C# 项目连接到本地 SQL Server 数据库 - Connecting to local SQL Server database from C# project 如何从Microsoft SQL Server数据库(在本地计算机上)迁移到LocalDB? - How to migrate from Microsoft SQL server database (on local machine) to LocalDB? 如何从 C# 中的本地 sql server 数据库中删除一行 - How to delete a row from a local sql server database in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM