Entity Framework migration with already deployed SQL compact database - sql

My situation: EF 4.3, private install of SQL Compact 4, .Net FW 4, c# winform
Problem: after the application was deployed there was the inevitable change requested that required me to create a new field in the only table in the SQL compact database. During app install the SQL compact db is placed in the user's Application Data folder so that it can be written to successfully. I updated the program and redeployed but the following behaviors are occurring:
uninstalling the old version of the app does not uninstall the SQL compact db in the user's Application Data folder
installing the updated version of the application does not overwrite the old SQL Compact db in the user's Application.
Since the new database with the added column doesn't get copied over it is breaking the application when the user runs it. My reaearch indicates that I should be using "automatic EF migrations" to solve my problem. In my situation mydesired strategy would be to do a quick check of the db table and add the missing column if necessary.
I am using EF the Database first way. I am having a hard time finding a good example that fits my situation and my desired strategy for fixing this.
Any help would be greatly appreciated! :-)

I don't think EF Migrations have anything to do with your problem. According to this, if you follow ClickOnce tutorials step by step, it should work. As suggested by that SO answer, you should check this page. Good luck!

Related

Entity Framework version 6.1.3 not getting open

I am building an empty MVC application using .net 4.5 framework VS 2012. Then I add entity framework version 6.1.3. After adding I right click on the models folder to add a new entity model. It opens the entity data model wizard where I am selecting "Generate from database". Then it is taking me to choose your data connection , but after a while its automatically closes. I don't know where's the problem is exactly. In web.config file I also changed the entity framework version from 6.0.0.0 to 6.1.3.0 , still it is getting close and not allow me to select my database. I tried EF version 4.0 and 5 as well but the same problem . I have one existing application on VS 2012 with EF version 4.4.0 , where some databases are already there. I have tried adding one more database there and it is adding there. then why not adding on my new application having the same configurations. What would be the problem ? Any help would be very much appreciated.
finally I found the answer after working around it for hours. what we need to do is , Go into view->Server Explorer and remove any "Data Connections". Then this worked again.

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.

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?

Handling database migrations when using Entity Framework

We are building an app in C# which uses Entity Framework with SQL Server 2008. We design the model using the designer in Visual Studio and auto-generate entities from this.
We're working on version 1.0. When we release 2.0, we'll need to make changes to the model and underlying database structure. I guess we need what's called "database migrations".
Traditionally, I've had a table in the database called something like 'version'. Whenever I've created a new version of my software, I've created database upgrade scripts containing ALTER TABLE statements. My software has checked the version table and run the upgrade scripts needed to upgrade the database to the 'software version'.
Is there some better way of handling this? It would be nice if I didn't have to write the alter table-scripts myself and write my own software to upgrade the database structure.
What I used to do when I did model first, is I pointed my model to a database that was purely for schema (so I had a myapp database, which was where my app ran, but my EF4 model was outputted to a myapp_schema database). When the myapp_schema was updated, I used Db Source Tools to generate the update scripts and make the myapp's database schema be the same as myapp_schema.
Chech this post out. It's about CTP4 of EF4, but it thing this is what you need.
http://blogs.msdn.com/b/efdesign/archive/2010/10/22/code-first-database-evolution-aka-migrations.aspx
Unforunately this isn't yet available. CTP5 was released a few days ago and as far as I know this is not yet included.

Sql 2008 Developer to Sql Azure Migration

Hi My company is deciding for switching its existing application to azure platform (only Sql Part). So we need to upload our db from local to cloud. For migration i came across various tools like
1. cerebrata 's tools
2. SqlAzure Migration wizard
3. Microsoft Sql Data Sync
4. Conventional Script way via management studio.
But all the above tools showed that they have limited capacity. A user cannot work flawlessly on either of the tool.
In cerebrata's tool - the main drawback was its field for Application User Name and Application Key , which my admin havent shared. Also there is manual mapping of fields between azure and local.
Sql Azure Migration wizard - generates scripts and executed too but with lots of error . I was using its version 2.1. Also it very slow. It seems that its a replica of Sql Srvr Mgmt Studio.
Sql Data Sync :- I found it cool as its a MS product but it has limitation too that it only connects with Windows Authentication based local sql server, or you need to explicitly allow the required but. Even after allowing while syncing , I got some Sql Azure Provisioning Error.
4 Sql Srvr Mgmt Studio :- This is most easiest way but requires a lot of manual work to do before actual migration. What i did is that I generated a script of entire db (almost 101123 lines of code for single db) and tried to execute on azure. On the very first time i faced some keyword mismatch error . Finally i removed all line after primary key declaration that With (Padding = Off ....)or something similar and also On Primary then i executed , but still got error on Set Identity Insert On. After doing a lot of hard work in removing unwanted lines waited more than 2 hrs to completed the script remotely, i got no Errors , errors and errors.
So you guys are requested to please suggest me any good alternative stated than above or i am lacking something and can do more with above.
Thanks
Amit Ranjan
I've faced a similar problem recently, running through the options you've listed.
You might give a try to Red-Gate beta for Azure (free for a few months). I found their tools to be quite good for SQL schema and data replication.
Never tried the Azure build myself, though (I migrated tables manually by the time I was told about the offer).