Skip to main content

How to manual create and restore a database from SQL Azure

In ultima perioada totul se automatizeaza, iar in multe cazuri in loc sa scriem cod, putem sa ne definim un proces prin intermediul unei interfete grafice. Acest lucru se intampla si pentru mecanismul de back-up (replicare) a unei baza de date SQL Azure.
In momentul de fata portalul ne permite sa facem usor back-up automat la date, la un anumit interval de timp. Acest lucru poate sa ne fie foarte folositor cand baza noastra de date devine corupta. Si nu va ganditi la cazuri precum cineva a spart Windows Azure si acuma poate sa faca ce vrea sau un hacker a pus mana pe string-ul de conexiune si isi face de cap. Exista cazuri mult mai simple cand baza voastra de date poate sa ajunga corupta, de exemplu un user sterge sau face update la anumite date, iar aplicatia voastra are un bug care cauzeaza ca datele sa fie intr-o stare inconsistenta.
Remarks: Sa nu uitati ca orice tranzactie, transfer de date, ... etc costa, iar backup-ul unei baza de date sau sincronizarea a doua sau mai multe baze de date costa. Daca masina era la noi in parcare ne costa curent si altfel de resurse. Iar Microsoft ne garanteaza ca orice baza de date SQL Server este replicata in 3 copii in acelasi data center.
In aceasta era, cand totul se poate configura printr-o interfata grafica extrem de prietenoasa, sunt cazuri cand trebuie sa face acest proces manual (din cod). In urmatoarele randuri o sa va prezint cum se poate face acest lucru.
Daca vrem sa facem back-up la o baza de date in acelasi data center avem la dispozitie comanda CREATE DATABASE, care in combinatie cu AS COPY OF poate sa faca minuni. Aceasta o sa genereze o noua baza de date, reprezentand copia fidela a bazei de date date ca sursa. Aceasta copie nu o sa fie 1 la 1 cu cea care exista in momentul in care apelati comanda ci o sa fie o copie fidela cu datele care erau in momentul cand crearea bazei de date a luat sfarsit (acest proces este tranzactional). Noua baza de date o sa fie accesibila dupa ce s-a facut commit la crearea acesteia. In timpul procesului de creare, noua baza de date nu este accesibila.
AS COPY OF [sourceServerName].[sourceDatabaseName]
Comanda trebuie sa fie executata pe serverul SQL Azure unde vrem sa cream o backup-ul.
Procesul de back-up intr-o alta baza de date poate sa difere o perioada destul de lunga (in functie de dimensiunea bazei de date), din aceasta cauza avem la dispozitie o comanda care poate sa fie executata pe serverul SQL Azure unde se face noua copie pentru a putea progresul la backup.
SELECT [db].[name], [c].*
FROM sys.dm_database_copies c
JOIN sys.databases db
ON c.database_id = db.database_id
Daca partea de restore se face destul de simplu, apare o problema in momentul in care avem o baza de date corupta si vrem sa facem switch la baza de date pe care o avem in backup. Acest lucru se face destul de usor daca redenumim baza de date cu numele original, iar baza de date corupta primeste un alt nume. Acest caz o sa functioneze data cele doua baze de date sunt pe aceiasi instanta SQL Azure.
MODIFY NAME = [MyDatabase_Invalid]
WAITFOR DELAY '00:01:00'
ALTER DATABASE [MyDatabase_Backup]
MODIFY NAME = [MyDatabase]
Ati avut nevoie manual sa faceti acest lucru? Eu am avut nevoie partea de restore sa o fac manual si sa o integrez intr-un tool. Pe partea de creare de backup am lasat totul sa fie configurat din portal.


Popular posts from this blog

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Run native .NET application in Docker (.NET Framework 4.6.2)

The main scope of this post is to see how we can run a legacy application written in .NET Framework in Docker.

First of all, let’s define what is a legacy application in our context. By a legacy application we understand an application that runs .NET Framework 3.5 or higher in a production environment where we don’t have any more the people or documentation that would help us to understand what is happening behind the scene.
In this scenarios, you might want to migrate the current solution from a standard environment to Docker. There are many advantages for such a migration, like:

Continuous DeploymentTestingIsolationSecurity at container levelVersioning ControlEnvironment Standardization
Until now, we didn’t had the possibility to run a .NET application in Docker. With .NET Core, there was support for .NET Core in Docker, but migration from a full .NET framework to .NET Core can be costly and even impossible. Not only because of lack of features, but also because once you…