Deploy existing data on ASP.NET web project from local database in Visual Studio to Azure database - asp.net

I've successfully deployed my ASP.NET project to Azure but the database has been deployed with no data, consequently throwing internal server errors due to functionality requiring that data. I can't see the exact error message as I'm unable to disable customErrors on my project (there's no webconfig file on Razor Pages)
I need to update my database on Azure with the data currently stored locally. How do you do this and is this possible?
N.B - I am using EF core with code-first migrations for data access

On the local machine open the "Microsoft server SQL management studio", connect to the local database server and navigate to the appropriate database. Rightclick on the database name and select "Generate scripts...". Select the tables you want to export, then click "next>". On this screen click the "Advanced" button, scroll down to "Types of data to script" and select "Data only". Now you can generate the script and copy that to a connection to the Azure DB, that can be an other query in de Management Studio or in the Azure portal.

Related

Problem publishing ASP.NET application with a SQL Server database

I've created an ASP.NET website which runs perfectly from Visual Studio. It connects to a SQL Server .mdf database file in the App_Data folder. I published the project using FTP. The live website cannot however connect to the database, as it is LocalDB, and my host uses a SQL Server (SqlException (0x80131904))
I uploaded an identical copy of the local .mdf database file from my computer to the host's SQL Server. I then tried to form a data connection with the server database from Visual Studio, however my host doesn't allow remote database access, for security reasons, resulting in error 40.
I'm using ASP.NET MVC in my application so I need access to the database to create models. My host has said "you can access SQL Server databases using ASP scripts running on your presence".
So my question is: how do I create models based on my host's SQL Server database when remote access isn't allowed?
When you're testing with Visual Studio, you should connect to the local copy of your database. When you're ready to publish your application, copy the database to the remote sql server and attach it. The copy of your application which is published should then connect to the uploaded database on that server.
That way you have one environment for testing and one for real use. There shouldn't be any need for Visual Studio to connect to the remote database.
P.S. To allow you to connect to different databases in different environments, usually you set your database connection string in the web.config file. So if you create different config transforms for each build configuration (e.g. debug and release) then visual studio will create the correct version of the config file when you do a Publish operation. See https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations for info about configuration transforms.

Publish ASP.NET project with local data on Azure

I'm quite new to ASP.NET and I encountered a problem when publishing my project to Azure. After configuring the connectionStrings in Web.config, I have successfully uploaded my local database structure to Azure. However, all tables on Azure are now empty, without any local data. So how can I upload both the database structure as well as the data in it? Thanks in advance.
To migrate an existing SQL Server database to Azure SQL Database you can export the schema as a TSQL script and then execute that script against Microsoft Azure SQL Database as follows:
1.Open SQL Server Management Studio and connect to an instance of the Database Engine.
In Object Explorer, right click a database to open a menu, select Tasks…, and then select Generate Scripts.
2.Choose objects to export.
3.Set scripting options. You have the options to save the script to file, clipboard, new query window; or publish it to a web service.
4.Set advanced scripting options.
You can also set the Types of data to script to one of the following based on your requirements: Schema only, Data only, Schema and data.
5.After the script is created, you have the option to modify the script before running the script against an Azure SQL Database to transfer the database.
You can now run this script on your Azure SQL Database.
For more details, you could refer to this article.
You have to create a post deployment script. If the tables are created just fine on your azure application, then you must define what default data they will have. So in your post deployment script you will insert the data you want.

Web App and Database Host on Azure

Hy Guys,
I'm new to Asp.net and Azure. I was working on ASP.NET with the help of this documentation link, When I publish my project on Azure by creating the Web App with latest portal on Azure, but it is only my application host on the Azure. And now i need to publish the my project database to Azure. In the present portal, the database option is not present there when we create the Web App on Azure to host the database as well with the Web project. But in the old portal as the documentation link guides us the database option is also present there when we publish our Web project on Azure.
Can anyone explain me how can i deploy my Web App existing database to Azure even if my Project has been deployed on Azure?
How can I deploy my existing Web App Database to Azure on the new portal.
If you use Code First Model of Entity Framework, you could just configure the connection string for your web application when you publish your web application. Entity Framework will generate tables for you automatically.
If there are existing data in your database which you want to migrate to Azure SQL Database. You could download a tool named Migration Assistant which will help you do it. For detail steps, link below is for your reference.
SQL Server database migration to SQL Database in the cloud
In the documentation he is using the old dashboard of Azure in which database option is attached with the Web App Publish procedure.
A small difference between old dashboard and new dashboard is that the creating Azure SQL Database feature is hidden when you create your app service. You need to click Explorer additional Azure services link to open the a new window for creating Azure SQL Database.
After creating a database, you could choose the database in the Setting tab when you publish your web application.
You also could create a database directly in Azure portal. After creating a database, you could get the connection string from the overview page.
If you make changes to a database schema and are using code first EF, will EF update your database schema when you redeploy your web app?
It depends whether you have enabled and run the migration. In the publish setting window, we could click the [Execute Code First Migrations] button to update the database schema .
If this button is disabled in the setting window, we need to run Enable-Migrations command in Package Manager Console.
In Visual Studio click menu Tool -> NuGet Package Manager -> Package Manager Console, input Enable-Migrations and run it.

import User Profile SQL Database to Windows Azure

Im a beginner that is thrying to setup my first website in Windows Azure. I have published it and made a Sql database inside Windows Azure.
In my local virtual machine I have SQL management studio that contain a User profile database. Is there a way to export that one and import to Azure?
You can deploy it directly from SSMS. Right click a database in the Object Explorer pane select Tasks - > Deploy database to Windows Azure SQL Database command:
In the Deployment Settings click the Connect button, and connect to your Azure Server:
Click Next:
Review summary, and click Finish:
After successful deployment connect to your Azure Server in SSMS and you'll see your database:
EDIT:
If you encountered an error during the deployment check the list of limitations in Azure SQL Database:
Azure SQL Database General Guidelines and Limitations
Azure SQL Database Security Guidelines and Limitations
SQL Server Feature Limitations (Azure SQL Database)
Also, here is a blog post on how to use SQL Server Data tools to migrate a database to SQL Azure: Migrating a Database to SQL Azure using SSDT
Hope this helps

Connection string setting while deployment

I have ASP.NET project and attached mdf database.I want to deploy it to remote server.I have just ftp account.The project works well on my local but ı had problem while deploying.I changed my connection string like. Please help me what is the problem ?
<add name="libraryConnectionString"
connectionString=" Server =.\SQLExpress;
AttachDbFilename= myusername#ftp.myserver.com/App_Data/LIBRARY.mdf;
Integrated Security=SSPI;
User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
You have to create a Ms-Sql server database (remote) along with user via control panel or you may ask to your hosting provider to create a database and user. Once database is created then you may execute your script (You may use Visual Studio Database Publishing wizard) and construct a new connection string for your web-app.
Have a look at MSDN article - Deploying a Database by Using the Database Publishing Wizard
The Database Publishing Wizard in Visual Studio enables you to deploy
a SQL Server database (both schema and data) to a hosting environment.
You can run the wizard by right-clicking a database in Server Explorer
and then clicking Publish to provider.

Resources