SQL Azure schema upgrade strategy - sql

i'm currently working on a asp.mvc application with entity framework as db backend which will be running on ms azure platform.
on my development machine i'm running a sqlexpress instance which hosts my development database (like i said may app connects via entity framework to it).
deploying the database schema from my local sqlexpress to sql azure is pretty easy via the entity framework database generation wizard (for whatever reasons the wizard always wants to create some clustered indexes which i correct manually in the generated sql file).
but i can't figure out a way to keep my data! the auto generated sql script always dumps all my tables and creates new ones...thats ok for initial setup, but not to upgrade a existing database.
there must be a nice way to perform a schema update without dataloss...please help! i have already tried sql management studio (r2) and SQLAzureMW (available on codeplex)...but they don't do the job :(
please don't tell me i have to code my own tool to do that!
looking for your help
thx
Edit: here's how i do it now
I use the SQL scripts created by the EF migration wizard for my local SQL Express and modify them myself to be compatible with SQL Azure. Is less work that one might think and works perfect :)

Have you tried to use BCP to export and then import your data? I believe you should be able to use BCP to export data from your SQL Express instance into a file, and then import data from the file into SQL Azure. The SQL Azure team has a blog posting that describes using BCP with SQL Azure - Link.
Additionally, in the future, the upcoming release of SQL Azure Data Sync CTP2 might be able to help you out.
Out of curiosity, what problems where you having with SQLAzureMW?

RedGate is famous for SQL server synchronization and data synchronization for deployment purposes.
They have a v9 beta out of their DataCompare and SchemaCompare products that are compatible with SQL Azure. I've been using both successfully and like them alot.
They are pricey when purchased, if you are a small business.
http://www.red-gate.com/Azure

This sounds vary similar to this question, the only answer to which is "wait for the next version of entity framework". I'll admit that I don't use EF, but I make my changes to tables the old school way with SQL Server Management Studio and scripts. ALTER TABLE FTW.
EDIT: If you don't have access to SQL Server Management studio, the new version of the SQL Azure portal includes a Silverlight based application that allows you to run queries and scripts

Related

How come I have no option to Create Partition?

I have no option to Create Partition on my table.
I thought maybe I had to create a filegroup first, but I have no option for that either under the database properties.
What am I missing?
*This is an Azure database.
We can create partition on table with T-sql like comments mentioned.
As you know, SSMS UI: Create Partition works well with local SQL Server, no option for Azure SQL Database.
Actually, not only the Create Partition option, there many options not support for Azure SQL database. Most documents only say the feature is supported in Azure SQL database with no details.
You could reference this blog:No UI dialogs in MS Azure / SQL Server Management Studio.
The reason is that SSMS do not have the full SSMS Support for Azure SQL database.
A lot of people complained about this in the SQL database feedback:
How can we improve Azure SQL Database?Full Management Studio Support
Such as:
"Graham Plowman commented ยท January 23, 2019 17:01
The regular version of SSMS has a UI around all the security and user
management options (and many others), making them a breeze to use.
When SSMS is connected to a SQL Azure database, all this UI
functionality is gone, replaced by bombing out to screens where one
has to type in SQL commands!!
Whatever next ? This was how we used to manage SQL server way back in
the 1990's with version 4.3 before SSMS became a serious tool!!
Kindly add the UI so it is the same as regular SQL installations.
Bombing out to SQL is a highly backward step."
There is still no solution for now.
Hope this helps.

How do I migrate the SQL server data to an older engine?

Here's my current dilemma: I need to migrate the database, including the data, from SQL server version 13 to version 12. The source is on an Azure box and the destination is on my local box. I can't install SQL server 2016 on my local box; that isn't an option. How do I do this?
I would recommend you to use SQL Database Migration Wizard
Can you try using SqlPackage to Export the Azure database?
I've recently done the opposite of you, exporting SQL Server 2012 databases to Azure SQL V12. I used a combination of SqlPackage and Visual Studio with SQL Server Data Tools.
Basically I made a SQL Project based on the source databases (SQL Server 2012 hosted), set the target platform to Microsoft Azure SQL V12 and fixed any errors and warnings that wasn't supported in Azure SQL V12.
I then did a schema compare between the source database and the SQL Project. With this I generated a script which I ran against a copy of the source database.
Lastly I used SqlPackage to make a .bacpac from the database I ran the script against, which I could then deploy to Azure.
If you do the opposite maybe it'll work. It is important that when working with Azure SQL that you have updated software.
It seems that the answer is in insert scripts, which I didn't realize was a thing. There's good information at How to generate an INSERT script for an existing SQL Server table that includes all stored rows?
Edit: Another answer says NOT to generate INSERT scripts to copy all the data from a DB. I tried it and it seemed to fail because of some truncation in the script itself (it ended up being over 11 GB). A developer I'm working with suggested the bcp utility (documentation at this link), which I have not yet tried.

ASP.NET MVC 4 Code First Solution Setup Using SQL Server 2012

I am planning to create a web application using ASP.NET MVC4 using the code first approach.
I am using Visual Studio 2012 and I have SQL Server 2012. What I would like to do is setup the solution in a way that I can use SQL Server instead of the default being SQL Express or localDB. I would like to have the solution regenerate the database if any changes are made to the models and seed the database with some test data when that occurs.
I have gone through a bunch of tutorials and they all seem to be using the SQL Express or LocalDB database. I was able to get the solution to generate the database on SQL Server the first time it was run, but after I make changes to the model such as alter the schema name from 'dbo' to lets say 'test' or change the table name, it doesn't seem to pick up those changes.
Can anyone give me some insight on how I might be able to accomplish this?
Thanks
All you need to do is have your connection string in the web.config pointing to your SQL server for it to use that server instance.
As for having it update on model change, have a look into DropCreateDatabaseIfModelChanges.
In your Global.asax you can set your database initializer like this
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DbContext>());
You will need a using statement too
using System.Data.Entity;
There is a free video guide to MVC4 by Scott Allen which can give you more info on Migrations and Code First (which is what you are asking about). The 4th section of the video guide has a 13 minute segment on Data Migrations which is a full walk through. If you can spare the time, watch that for a full detailed guide.http://www.asp.net/mvc/videos/pluralsight-building-applications-with-aspnet-mvc-4
I might point out this is only useful in development and there is no way to make it work for production as you would lose your data. If you need something that is suitable for a production environment look into SSDT (SQL Server Data Tools). You can manage your database as a SQL project in your solution and deploy updates using a DACPAC file. The file manages all the updates in production and can be set to protect against data loss. You can change and deploy your Db from your project and still use EF with database first and EF models etc. All you do is make your changes in the Db project and hit debug to update your test Db. When publishing you can choose to export the DACPAC for updating live.

Database reverse engineer installation

I have an existing database (SQL Server 2008 R2), and my goal is to have a project that can install the same database as I already have.
i.e the project will read the schema and the data, and will be able to duplicate the existing data and schema.
This tool needs to save the database information to disk so I will able to install the database on different machines.
Can I do it with Visual studio 2010 database projects?
Is it a simple task?
(The reason I am asking is that I already have such a project that installs my database, but this tool is very old(~2000).
That old project is one big mess, it has C#, java, sql, batch files and some 3rd party tools and has many more capabilities than I need for my current product..)
Thanks.
Use SQL Server Management Objects (SMO) to create a snapshot of your source db and then restore it to the target server.
More on SMO here: http://msdn.microsoft.com/en-us/library/ms162169.aspx .
A nice tutorial here: http://www.codeproject.com/KB/database/SMO_Tutorial_1.aspx
The easiest way is to backup using SQL server management studio. Then move the backup file to the second server and there restore it with SQL server management studio. If you need SQL code to do it (instead of GUI way), just drop a comment...
This codeplex project has a basic library that does that if you like to roll your own and has two sample projects for migration/comparison tasks.
http://dbschemareader.codeplex.com/
Also the commercial option is to use Sql Redgate's tools. They are expensive but worth every penny if this is a mission critical database. On the otherhand, if you are just using a db as an alternative to a file, say in a embedded scenario, it might be hard to justify such an expensive tool.
Have you tried DBSourceTools ? http://dbsourcetools.codeplex.com
It is an open-source database versioning tool that will script out all database objects and data to disk, and then re-create the database on another machine.
It has all of the features that you are looking for.

Offline database solution for sql server

Here's task: We have an sql server database. which is hosted at our server. What we need to do is: we need to create a non-techy-users interface (basically insert/edit forms) and let these non-techy-users to install this database locally, since they are located in the areas without internet connection. Then when they're done using the database we get the data from them and inster it in our database.
The biggest concern is that it is not trivial for non-it people to install sql server. Can you please advise me what solution should I choose? Simple Access should work fine, but i really do not want to mess with it and have data conversion back and forth between engines.
Sync Framework for SQL Server: your application uses a lite weight, embedded SQL Server CE (no installation, just a couple of DLLs deployed along with your app) and the sync framework manages the synchronization with the 'mother ship' SQL Server.
Out of interest, why do they need their own installation? Can't you create a new database on your existing instance?
If you're looking for an easy way to create insert/edit forms on your database, have you considered looking at Microsoft's new LightSwitch product (currently in Beta) or Microsoft's Dynamic Data?