📜 ⬆️ ⬇️

Some freebies in Microsoft Azure or create free SQL Database in the cloud

Hello everyone, this small manual will be useful to those who want to use SQL Database in the Azure cloud, but for some reason it still does not. As you know, Microsoft Azure is a cloud hosting service that has recently been free for students. Today I want to talk about a way similar to what was described in the article of my colleague MSP (but slightly different) how to use SQL Database in the cloud absolutely free.



In the Microsoft Azure cloud, it has long been possible to host free Azure Web Sites. Separately, I’ll say that students in the DreamSpark program can access Azure Web Sites, MySQL Database (up to 32 MB) and some other Azure cloud features. Recently, on a DreamSpark subscription, the Azure SQL Database is available for students, but only up to 32 MB. But, if you can’t get more for free, but you really want to, then you can.
To help us in creating a project with a free SQL Database in the cloud comes SQL Server Compact, but first things first.

Microsoft® SQL Server ™ Compact 4.0 is a free built-in database that can be used to create ASP.NET websites and applications for Windows computers. SQL Server Compact 4.0 takes up little space and supports the private deployment of an executable module in an application folder, simplifies development in Visual Studio and WebMatrix, and provides easy schema and data migration to SQL Server.


')
The SQL CE database is in the same .sdf file. As for the limits on the size of such a database, it is as much as 4 GB! The .sdf file can be simply copied to the target system for deployment, which is what we will use.

First, take a project that already uses a SQL Server database or create a new one.
I will use a small ready-made project that uses SQL Server and the Entity Framework.

First, through NuGet, install "EntityFramework.SqlServerCompact". That's enough, because during installation, other necessary packages will be downloaded by themselves.



Next, you need to change the connectionString and bring it to the form:

<add name ="DefaultConnection" connectionString ="Data Source=|DataDirectory|DB.sdf" providerName ="System.Data.SqlServerCe.4.0" /> 

NB database format is * .sdf



After launching the project, the SQL CE database file will appear in the App_Data folder of our application.



The next step is to include this file in the project. To do this, add the * .sdf file to the App_Data folder in Visual Studio.



Now everything is ready to deploy the application in the cloud. As mentioned earlier, you can host free Azure Web Sites in Azure. You can create a site directly from Visual Studio during deployment setup, but to avoid mistakes, I recommend doing this through the Azure portal .





Next, you need to return to Visual Studio and publish the application by selecting the created web application in the second step.





After successful publication, the site will open automatically and you can see the result.



Microsoft SQL Server Compact works fine in Azure, but this method with database deployment in the cloud can be applied to various ASP .NET hosting sites, where SQL databases are expensive / only paid.

This method has one drawback, compared with the method described in this article , namely, the database with SQL * .sdf is not as convenient to work as with * .mdf. To view the contents of the * .sdf database, I use LINQPad 5 .

To do this, I download the database file (via the VS Online extension installed in Azure) and upload it to LINQPad.







That's all! As a student, I can say that this kind of “freebie” is very attractive, because the SQL Server Database in the 4 GB cloud does not roll on the road!

Source: https://habr.com/ru/post/275969/


All Articles