简体   繁体   中英

Changing from local database to SQL Server hosted on a server

So I'm fairly new to MVC and C# in Visual Studio. 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

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. 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.

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).

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.

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. 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. 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

I would create a .sqlproj from the LocadDB version, then publish that to your SQL Server. Change the connection string in your MVC project, and you should be good to go. 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.

SQL Server:

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

MySQL:

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

Let me know if this helps.

Authentication: SQL Server Authentication

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM