3

So, i built my application using Entity Framework database first. My database only has 2 tables, it's very small.

I've seen some videos on YT about deploying to Azure but looks like all of them use CodeFirst approach, then use enable migration on Package Manager, and then they publish the application using a checkbox to execute code migrations.

But since i built my application using Database First, i can't use this feature. The enable-migration feature only works for Code First.

So, what can i do to put my database on the Azure and deploy my application ?

EDIT WITH SOLUTION:

On SQL Server Management Tool, if you click with the Right Button on your Database and go to Task, you'll find the following option "Implant database on Azure SQL server Database".

You just need to specify the instance of the server in the cloud, the login and password, and click next and it'll deploy the database for you. IMPORTANT: FIRST, you need to make a connection with your local machine and the Azure Sql Server. To do that, you need to insert the IP Adress of your machine in the firewall definitions of the server on the cloud. It's well explained in this link: https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/database-first-development/publish-to-azure

Then, after you migrate the database, you just need to get the ConnectionString of the new database that you inserted on the AzureCloud, and then you go to your application on Visual Studio, Publish, update your connection string and deploy.

2 Answers 2

3

Follow these steps you will be good to go:

  1. Right-click the project and select Publish.

  2. Select Microsoft Azure Websites.

  3. Select New to create a new web app.(If not login, Enter your credentials)

  4. Fill the necessary details and Create new server for the database, and provide a user name and password for this new database server. When finished, click Create.

  5. Leave values unchanged, those are your connections values.

  6. Click ellipsis (...) next to the database connection, Note the name of the database server and the database.

  7. Click OK and in the Publish Web window, click Next to see the preview. Click Publish.

After publication, the site is immediately launched in a web browser. Your site has been deployed, however, you will receive an error since your table has not been published yet.

Publishing database to SQL Azure

  • Before publishing your database, you must make sure your local computer can connect to the database server. The firewall for your database server restricts which machines can connect to the database. You need to add the IP address of your computer to the allowed IP addresses for the firewall.
  • Login to your Azure account through the Azure portal.
  • Select your new database and select Manage.
  • You must configure your database server to allow connections from your computer. When you select Manage, you are asked to add the current IP address as permitted to the database server. Select Yes.
  • There is a chance that the IP address you added in the previous step is not the only IP address you need to configure for connections. You can attempt to login to the database to see if the connections have been properly set up. Provide the user and password you created earlier.

If you receive an error message, you need to add another IP address. Click the error message to see more details about error. In the details, you will see the IP address that you need to add. Note this IP address.

  • Close this login window, and return to the Azure portal. Navigate to the Dashboard for your database. Click Manage allowed IP addresses.

  • You must now add the IP address from the error message. Either change the range of allowed IP addresses to include the one from the error message or add that IP address as a separate entry.

  • Save the change to allowed IP addresses. Click Manage, and try logging in again to the database. You may need to wait a few minutes before the allowed IP addresses are correctly configured for the firewall. When you can successfully log in the database, you have finished setting up your connection to the database.

You can leave this management window open because you will check the result of your database deployment shortly.

  • Return to your database project. Right-click the project and select Publish.

  • In the Publish Database window, select Edit.

  • Provide the name of the database server and your authentication credentials for the server. After providing the credentials, select the database you created from the list of available databases. By default, Visual Studio sets the name of the database field to the name of your project which might not be the same as the database you created.Click Ok. Click Publish.

and you are done

learn.microsoft.com has good documentation

Sign up to request clarification or add additional context in comments.

3 Comments

The new interface portal of azure doesn't have this "Manage option". It is on "Define Firewall of the server" ? It was the only option that i found...
i managed to connect to the azure database... but i can't find how to publish... in the link you mentioned, in that part: "In the Publish Database window, select Edit. Provide the name of the database server and your authentication credentials for the server. After providing the credentials, select the database you created from the list of available databases. By default, Visual Studio sets the name of the database field to the name of your project which might not be the same as the database you created." Well, i can't find this option Publish Database when i click on Publish...
looks like the database the he used on his project was from visual studio... my database was created on the SQL Management Studio...
1

To publish your database, you could click the Settings link as following.

enter image description here

On the setting panel, you could set the connection string and choose update database during publish.

enter image description here

4 Comments

I don't have this checkbox in my option... here the option is "Execute Migrations with Code First" but since i used DataBase First to generate the model of Entity Framework, that checkbox doesn't work for me...
Which version of VS do you use? Mine is Visual Studio 2017 Community.
Mine is the same... btw, i made it !! It turns out that, by lucky, i found an option in the Sql Server Management Studio that was Task -> Implant Database on SQL Database of Azure, it's like a wizard, that do the same thing of the publish database of Visual Studio. You specify the instance of the server, put the user, password, and the database it's migrated to azure. It save me haha ! i'll edit the post with the solution
Glad to hear that you found the solution and thanks for sharing the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.