Recommendations for supporting both Oracle and SQL Server in the same ASP.NET app with NHibernate - sql-server

Our client wants to support both SQL Server and Oracle in the next project. Our experience comes from .NET/SQL Server platform. We will hire an Oracle developer, but our concern is with the DataAccess code. Will NHibernate make the DB Engine transparent for us? I don't think so, but i would like to hear from developers who have faced similar situations.
I know this question is a little vague, because i don't have Oracle experience, so i don't know what issues we will find.

You can easily use NHibernate to make your application database-agnostic by following some basic practices:
Design your object model first.
Do not use any database-specific code. You need somebody with good C# experience, not an Oracle developer. Do not rely on stuff like triggers, stored procedures, etc.
Let NHibernate generate the DB schemas at least initially (you can tweak things like indexes later) It will choose the best available datatypes for each DB.
Use a DB-agnostic POID generator (hilo or guid) instead of sequences or identity.
Try to avoid using SQL. HQL and Linq work fine in 99% of the cases.
Avoid NH features that are not supported by all of your target DB (for example, Future, MultiCriteria, etc)
NHibernate has a great community. You can always ask your questions in http://groups.google.com/group/nhusers besides posting here.

There are three things to consider - the ISession object, the SQL queries that are generated and your plain-old-clr-objects that are mapped to tables.
NHiberante will generate the required SQL queries based upon the chosen database dialect. If you configure NHibernate to use the SQL Server dialect it will generate SQL server correct SQL statements. This can easily be configured dynamically at runtime based on configuration.
You also need to configure your session to connect to the right type of database. Again, various configuration methods can support dynamic ISession creation at runtime.
Your actual data objects which are mapped to tables should not need to change based on database choice. One of NHibernates strengths is flexibility it provides in supporting multiple databases via a (fairly) simply configuration change and some up-front architectural thought.
See http://codebetter.com/blogs/karlseguin/archive/2009/03/30/using-nhibernate-with-multiple-databases.aspx for some examples of how you might abstract the underlying database away from the creation and usage of NHibernate.

Related

Schema based multi-tenancy with hibernate on MS SQL Server

I'm implementing a multi-tenancy capable application based on Java 8, Spring Boot 2 and JPA/Hibernate 5
There are different approaches to this, I chose the schema based approach. The Hibernate docs also write about support for this.
I also looked at some tutorials
But it seems like everyone on the net uses native SQL to switch schema. Not only do I have to support multiple DBMS - but I could provide different implementations - but it seems like MS SQL Server does not support setting a schema for the duration of a connection only.
There is a setSchema(String) method on the JDBC Connection object, but MS does not support it (also verified by looking at their source on Github). Not only that, but I can't find a way using T-SQL either.
Is there another way to set the connection schema in my ConnectionProvider, or do I have to switch to a completely different approach (e.g., discriminator column based)?
FYI, the schemas have to be dynamic, since tenants can be created via the UI.
IMHO, the best multi-tenant strategy for your application requirements, would have been COLUMN DISCRIMINATOR strategy ... But it's still under development and not available with the last Hibernate 5.3.2 release.
FYI, the schemas have to be dynamic, since tenants can be created via the UI.
Using schema strategy with this high portable requirements is very hard to implement for some reasons:
Schema concepts are very different across database vendors
Hibernate multi-tenant solution is yet very light
I suggest, you lower your portable requirements and choose only database vendors giving you the tools for effective multi-tenant schema strategy.

Entity Framework with Multiple DB Engines

We have a few .Net application that we would like to start using Entity Framework 5.0 but the problem is that our customers can choose to use one of any of the following database engines:
SQL Server (95% of Customers use this engine)
Oracle (3% use this engine)
DB2 (2%)
So as you can see an overwhelming majority of our customers use SQL Server. So my question is that assuming that each database engine will have the same exact schema layout then all we should have to do is to change the entity connection string to target each of these engine types, correct?
Sorry if this seems to be a simplistic question but I just wanted to make sure that I was on the right track here.
I do not know Entity Framework, but the are many differences between the DB engines.
For example the security, in DB2 is always external (OS secutiry), in Oracle most of the time is internal. Procedure language is different, and I hope you don't use it for a multi-platform application.
The best is to try the execution with each database, and tune the procedure in order to work in all of them, but I think you have to do more that change the connection string.

How to support both PostgreSQL and SQL Server in a Node.JS application?

I'm currently developing a Node.js app that needs to be able to switch between PostgreSQL and SQL Server databases. Both databases have identical tables and the operations will also be identical (basic CRUD, nothing fancy).
I've done research, and know that there are enough libraries around to access both databases.
Ideally I'd like to use a ORM and just let that handle the differences. However, I can't seem to find an ORM framework that does both. In fact, I can't locate any ORM that supports SQL Server, while almost all support Postgres.
So my question: is there an ORM that supports both? And if there isn't, are there other abstraction tools/frameworks around that will make my developer life easier?
There is a certain amount of YAGNI here, but if you are unable to find an ORM that supports both, your next best bet is to just use an Adapter Pattern and ensure you're not using the ORM directly in your code, but through a wrapper. Then if / when you need support for SQL Server, you can create the implementation for the wrapper which will replace the PostgreSQL implementation.

Choosing between Data Access Block 5.0 or Entity Framework 4.0

I'm going to develop a Web Application with two essential requirements:
Total independence of DBMS. The application should work with different DBMS like Oracle, SQL Server and MySQL. That is, Client 1 use this application with SQL Server, but he wants to migrate to an MySQL Database. The application should be able to work with this new DBMS without needing to make changes to the application code. The only change I want to do is to change the connection string.
Scalability. ie, we will have a clustered SQL Server installation.
I know that Data Access Block is able to handle different DBMS and I assume it won`t be an issue to meet the scalability requirement, but I don't know if this is the case with Entity Framework.
Choose Entity Framework, for a couple of reasons.
First, EF is where Microsoft is putting all its data access emphasis for the foreseeable future. Entlib's data block is primarily there to support folks already using it.
Second, Entlib will give you a regular API, but it doesn't insulate you from the differences in SQL statements. Oracle in particular does stuff with cursors no other database does (or needs to); EF at least attempts to give you a uniform API.
As far as scalability, that's all about the design of your database and application, no data access tool will give you that.

LINQ with existing databases and unknown schema

I'm working on a database heavy project, where the Microsoft SQL databases are very mature (16 or more years-old mature), and an old product uses VB6 and ADO to generate sql which interacts with the database. I've been given the task of porting/re-writing the ancient version with a new .NET version.
I'd love to use LINQ-to-* to ensure easy maintainability, but having tried for the last several weeks I feel like LINQ-to-SQL isn't flexible enough, LINQ-to-Entities has too much overhead, and LINQ-to-Datasets is pointless since I would be just as happy using Ado.Net.
The program operates on two databases at once: one is a database with a very consistent schema containing meta-data, and the other a database which has a varying schema, is tightly coupled to the meta-database, and dictates what information from the meta-database you are interested in at any given time. Furthermore, I need non-LINQ information from both databases (such as system-stored procedures, and system-tables).
Is there any way to use LINQ intelligently here? I'd love the static typing, but if I can't have it I don't want to force my square app into a round framework.
Just an FYI, you can get access system tables (and sys stored procs too?) using LINQ. Here is how:
Create a connection to the server you want.
Right-click the server and choose Change View > Object Type.
You should now see System Tables and User Tables. You should see sysjobs there, and you can easily drag it onto a .dbml surface.
Above was stolen from this post.
The best answer seems to be to use ADO.NET completely. I have the option of using Linq-to-Sql over the metabase and ADO.NET for any other database access, but that would make the code feel too inconsistent for me.

Resources