Entity Framework Oracle and Sql Server - how to build a database independent application - sql-server

We are trying to build a data access layer for using both Oracle and SQL Server (not at the same time).
We use EF Model-first for creating the model and the create the SQL scripts for building the database. Our first thought was to create 2 EDMX files, one for each type, and use the appropriate one depending on the client's need. We are using the Oracle and SQL Server database generation workflow and DDL generation template to create the scripts for each database.
Our main problem is when the database schema changes we do not want to drop and recreate the DB but only create the migration scripts to update the DB base on our model (clients have many data that will be lost).
We use EF power pack for extracting the migration scripts for SQL Server but there is nothing like it for Oracle.
We want help to find a good data layer (1 EDMX for both Oracle and SQL Server if it's possible and not complicated) and a good way to generate database changes from our model to update existing client DBs in case of a new application release
We found this as a starting point
http://msdn.microsoft.com/en-us/data/ff830362 but there is not mention for Oracle support.
We have tried code-first and EF Migrations but Oracle failed us again on the DB creation and migration.
Any recommendation on how we can accomplish this?
Thank You

There is no way to have single EDMX for both SQL Server and Oracle. EDMX consists of three parts CSDL (entity definition), SSDL (database definition), MSL (mapping between those definitions). SSDL must always target concrete database so you need at least separate SSDL for Oracle and SQL Server and if you are lucky you will not need separate MSL as well (mapping must be exactly same which will probably not happen if you are using any tool to generate the database).
So you always need at least part of EDMX file for second DB and manually maintain it.
If you need DB migration supporting Oracle you must look for tool from Oracle (or third party). For example RedGate offers tools supporting schema migration for both SQL Server and Oracle.
Visual Studion Premium and Ultimate edition also offers tools for comparing database schemas. It by default supports only SQL Server but Toad Extensions should add support for Oracle as well.
Once you have any of these tools you just need to compare schema deployed on customer server with your new schema and the tool should create migration script for you.

The best article I found on this topic is from Paul Reynolds Blog.
Try to go through from part 5 to part 9.
There are so many gotchas about Oracle mentioned there... is very helpful!

Related

SQLite schema based on SQL Server DB schema

I maintain a Windows based application backed by SQL Server DB so there is a set of SQL entities, like tables, views. With time I add new features and fix bugs so schema of the tables and views changes. Once I need to deploy a new version of the application I deploy the DB part by relying on DacPac/DacFx which automatically generates a difference between already deployed DB and the supplied DacPac so the already deployed DB is altered to match the DacPac's content. This way I don't have to write a code which compares 2 schemas and then generates a difference - DacFx does that for me.
That works well but now I need to expand the application so it also supports SQLite DB, I will for sure have to create a new application layer working with SQLite which is doable but one place I need help with is being able to create and maintain SQLite DB schema in the same way I do for SQL Server with DacPac/DacFx so a difference in schemas is computed and applied. While doing that I ideally want do write the SQL schema once so it could be applied to SQL Server as well as SQLite. Ideally, I need to generate SQLite schema based on the schema specific to SQL Server.
I looked into sqldiff which is capable of generating difference between 2 SQLIte DBs and thought I could:
use a technique from here to migrate SQL Server schema to SQLite
generate a temporary SQLite DB based on the generated above schema
compare the above deployed temporary DB to an existing SQLite DB by using the sqldiff and finally apply the difference to the target SQLite DB
but the sqldiff, as stated in the Limitations section:
The sqldiff utility is not designed to support schema migrations
In addition it has limitations around views:
The sqldiff.exe utility does not (currently) display differences in
TRIGGERs or VIEWs.
So I interpret that like that tool could probably be used for some migration cases but it is not really recommended.
How do you suggest generating and applying the schema differences?
I'm also interested to know how others solve the task of incrementally updating schema of their SQLite DB even if I take SQL Server completely out of equation and would instead maintain SQLite schema, in the source code, only. Does everyone create their own schema comparing tools instead of using something similar like DacFx in SQL Server world?

best way to transfer tables from SQL Server to Azure SQL?

I recently moved a SQL Server 2012 database from an old web server to Azure SQL. I also keep a copy of the database on my personal machine which is now running SQL Server 2019. During development, I frequently make changes to tables on my local machine and then need to transfer those tables to the server. I used to do this using a Visual Studio SSIS package. It was very easy. I used the "Transfer SQL Server Objects" task to select one or more tables, specify whether the existing tables should be dropped first, and replaced the tables on the server. The "Transfer SQL Server Objects" task does not work when trying to transfer objects to Azure SQL because it uses the "USE" statement. There must be an easy way to transfer tables to an Azure SQL database. I've used the "Microsoft Data Migration Assistant" and it works great for the initial migration, but does not allow you to replace tables. I feel like I am missing something very obvious because transferring tables is a routine task and there must be an easy way to do this with Azure SQL.
Manually managing and synchronizing different database versions can be time-consuming. The Schema Compare addon facilitates database comparison and provides you complete control when syncing them — you may filter particular differences and categories of differences before making modifications. The Schema Compare addon is a trustworthy tool that will save you time and code.
Hence, the Schema Compare extension provides an easy-to-use experience
to compare two database definitions and apply the differences from the
source to the target. MSFT Ddocument which could be usefull : Schema
Compare extension- here and How to: Use Schema Compare to Compare
Different Database Definitions - Here.

How to connect the Data Modeler with SQL Server 2008?

I want to document a SQL Server 2008 database. I have been asked for the Diagram and the specifications of the tables, fields, data type, etc. (Data Dictionary).
The problem is that I can not find a program that suits my requirements. The Erwin Data Modeler has a reverse engineering tool, but it is not useful because it does not allow me to specify only the tables that I want to diagram, at the very same request the schemas (But it is in this program that I am asked to do the diagramming) . SQL Server Management Studio is not an option because it is the same that manages the Databases (it implies modifying the DB in some way) and it is not very flexible with the choice of tables.
So I resorted to Data Modeler works perfectly with an Oracle database, you can make diagrams, generate scripts (the latter helped me to pass diagrams to Erwin), and even generate documentation of objects, etc. But I have not been able to connect it to SQL Server 2008 to do the same thing I did with Oracle. I downloaded the jtds-1.2.jar to make the connection but I do not know exactly how to do it.
In summary I need a program that allows me to choose the tables to which I want to diagram (These are things that are achieved with the Data Modeler) and then be able to open them in the Erwin (With the script that generates the latter) which is the target program. And also the field documentation, although this is a secondary issue to the question.
It would be helpful if you know of any other method, program or procedure.
download from sourceforge jTDS v1.3 or 1.3.1
get the JAR out of the zip
add it to your sqldev folder
open preferences in the tool, and go to third party drivers, under database page i think, and then when you get to connection dialog, there will be a SQL Server and Sybase connection type
i talk about this in more detail here
You can connect to a SQL 2008 db and RE the databases into one or more data models, and then generate data dictionary reports and DDL scripts. And a lot more..get v4.2 if you want to generate HTML reports that include the diagrams themselves.

What kind of database the Sql Server Migration Assistant uses as an internal data repository?

What kind of database the Sql Server Migration Assistant uses as an internal data repository and stores it in the source-metabase.mb file?
I guess that this it is one of standard tool that I could use to open and edit some entries (I need to autamatically add some custom scripts for tables with BLOBs data migration )
You could also just suggest the way how to check most popular database formats: SqlServer Compact, MySQL, Access..
it is one of standard tool that I could use to open and edit some entries
I would not count on it :) It was a proprietary metadata format that has nothing to do with DB products that SSMA supports. It can store metadata for representing Oracle and also SQL Server among others, obviously formats are not connected with file structure that actual DBs use. SSMA format has no open docs, also it may fail to synchronize your changes after manual intervention if you reverse engineer it (due to the fact it was designed just as the migration tool to target SQL Server and was supposed to mostly create new objects there based on source database counterparts).
Can you just write some stored procedures or triggers in your database? For most DBs metadata is exposed as special tables/views anyway. Probably you need to do it only for SQL Server as it's your target db after migration, right? Looking into ways to directly parse or manipulate files managed by "big" DB (like SQL Server or Oracle) doesn't seem to be a good idea for most scenarios. (except digital forensics, for example)
SQL Server metadata related views are here and functions are here. You may profile your SQL Server instance while connecting to it with SSMA just to get some feel what it does to extract metadata (object names, columns of tables, source of SPs etc.)
Data manipulation is pretty much clear from the DB side if you need it too.

Is it possible to use the same Entity Framework model for both SQL Express & SQL CE 4.0?

I'm currently working on a SOA project where at some locations it would make sense for the service to use a lightweight database (SQL CE 4.0) while at other locations a more robust database is desirable (SQL Express right now, but possibly scaling up to larger editions).
Even though the model and table structure is identical for both SQL Express and SQL CE, I can't figure out how to get Entity Framework to use the same EDMX to work with both databases. The conceptual model is identical for both, and the only difference in the storage model is the provider name that is used to access to the database.
Am I missing something, or do I need to keep two basically identical models around, one for each database.
I'm using .NET 4.0, Entity Framework and VS 2010 SP1
Unfortunatelly I think you have to create two separate SSDLs with different provider and manually keep them in sync (this can be actually done by some post build script wich will copy ssdl file and replace a provider). Still you have to be sure that table structures are same:
same table names
same column names
same data types
The last point can be critical because as I know SQL CE doesn't support some types common in SQL Server. For example I think navarchar(max) and nvarbinary(max) is not supported in SQL CE.
To force EF to create SSDL file instead of including it as a resource change Metadata Artifcat Processing (in properties of EDMX designer) to Copy to output directory and modify connection string. Here is a related article.
You can do this if you don't mind switching to Code First. Gallery Server Pro 3.0 uses Code First to target either SQL CE or SQL Server, depending on the user's preference. There is a single code base with the only difference being the connection string in web.config.
It's an open source project so you can see how it's done in the code.

Resources