Programming for various database - database

I'm wondering for those enterprise programs, how do they link to various type of database just by stating the connection string?
Issues like different syntax, variable type will definitely be there.
Apart from stored procedures for each type of database, how else do they handle in terms of their programming?
1 way that came to my mind is just if else checking of database in order to populate different query.
Asking as I'm curious while using a engine which is built in C++ and jsp, but could support SQL Server, Access, MySQL, Oracle

ORMs tackle this problem by introducing a level of abstraction between the database and the domain model. For example with Hibernate you change the connection string and the dialect and HQL queries and Criteria APIs are automatically translated into the proper SQL for the target database.
Of course this assumes you never write a single line of SQL in your application or anything which is specific to the database.

Related

What does "implicit meaning" means in terms of database design and what should I understand under "DBMS" and DB System Language?

I have picked up the book named "Fundamentals of Database Systems, 3rd Edition" by Elmasri and Navathe to get a basic understanding first. I have started reading it from the first chapter.
It defines a database and data as "A database is a collection of related data. By data, we mean known facts that can be recorded and that have implicit meaning."
What does "implicit meaning" mean here?
"A database can be created and maintained either by a group of application programs written specifically for that task or a database management system."
I think application programs are the queries you use to, e.g. , retrieve data or update data etc., aren't they?
What should I envision when I think of a DBMS at its core?
Examples of updates (like "Change the class of Zarah from Freshman to Sophomore") have been given. Then it goes like,"These informal queries and updates must be specified precisely in the database system language before they can be processed."
What is this Database System Language? Querying Language like SQL, MySQL etc. ?
What does "implicit meaning" mean here
I believe it means that value in a table (say 3395512) doesn't have meaning without knowing what the attribute is, and what relation it is a part of.
I think application programs are the queries you
use to, e.g. , retrieve data or update data etc., innit?
Not quite. Applications programs in this context are the applications software developer write to access a database. For example this web site reads and writes to a SQL Server database, or the tools/jobs that that update data.stackexchange.com. Compare this to Sql Server Management Studio (SSMS) which is a tool that isn't written for a specific database.
Can somebody give an example? By example I really mean the simplest
example of a DBMS on the planet earth (computerized DBMS, and not the
hand-written file system, ofcourse!)
The term DBMS is typically used to describe products like SQL Server, Oracle, MS Access, MySQL, SQL Lite, etc. Some people also apply the term DBMS to the Admin and Developer tools these products come with.
What is DB System Language? Querying Language like SQL, MySQL etc. ?
Typically it's some vendor specific implementation of SQL. However many databases also provide APIs that are able to access the database without SQL, although not nearly as popular.
Implicit data means a value of ,any data type, stored in one column and row intersection whose meaning and what that really is can only be understand by relating that value to another value in another column and row intersection on the same row and along with their attributes name.

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.

Entity Framework, No SQL server, What do I do?

Is there seriously no way of using a shared access non-server driven database file format without having to use an SQL Server? The Entity Framework is great, and it's not until I've completely finished designing my database model, getting SQL Server Compact Edition 4.0 to work with Visual Studio that I find out that it basically cannot be run off a network drive and be used by multiple users. I appreciate I should have done some research!
The only other way as far as I can tell is to have to set up an SQL server, something which I doubt I would be able to do. I'm searching for possible ways to use it with Access databases (which can be shared on a network drive) but this seems either difficult or impossible.
Would I have to go back to typed DataSets or even manually coding the SQL code?
Another alternative is to try using SQL
Install SQL Server express. Access is not supported by EF at all and my experience with file based databases (Access, SQL Server CE) is mostly:
If you need some very small mostly readonly data to persist in database you can use them (good for code tables but in the same time such data can be simply stored in XML).
If you expect some concurrent traffic and often writing into DB + larger data sets their performance and usability drops quickly. They are mostly useful for local storage for single user.
I'm not sure how this relates for example to SQLite. To generate database from model for SQLite you need special T4 template (using correct SQL syntax).
Have you tried SQLite? It has a SQL provider, and as far as I know EF supports any provider. Since it's file-based, that might be a plausible solution. It's also free.

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

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.

Queries for Sql Server and Oracle

I'm developing an asp.net application with Database factory pattern which allows the application to support both Sql Server and Oracle. I've created an abstract class that has the methods common to Sql Server and Oracle, like the CreateConnection and CreateCommand methods. This class is implemented by SqlServer and Oracle classes. Now, is there an easy way to write in-line sql queries with parameters common to both Sql Server and Oracle. I mean, I understand that we use "#" symbol in Sql Server and ":" in Oracle for parameters. Just for this reason, I'm writing queries twice in each of the class. Is there a way to write such queries common to both the databases? (or interpret the parameters from one common query?)
Thanks.
The only way to write one query that will work for both Oracle and Sql Server is to use only the syntax that is common to both platforms. Once you use features that are different between the two languages (like parameters or joins), you either have to write two different queries or hack together a "translator" class that converts a query from one platform to the other.
I've done a lot of this type of programming (database-agnostic software), and with .Net a relatively pain-free way of doing this is to write your main application to work entirely with ADO.Net DataTables/DataSets, with a wrapper class that handles generating the DataTables from either Oracle or Sql Server tables under-the-hood, and also handles persisting changes made to the DataTables back into Oracle or Sql Server. This approach isolates your DB-specific code in one place, although it's not necessarily a viable approach if the data your application needs access to is large.
You could write some kind of translator, but I would suggest that in some cases you'll need to write db-specific code for performance reasons anyway, so you'll have to put up with the maintenance burden of two versions of some queries.
What is the point of using ORACLE and not using all its non standard functions (analytics, pivots etc) ? ORACLE is a powerful tool.
Other DBs have there own strenght also, so why use the lowest common denominator just to be able to work on ALL of them? You will just lose in performance.
Just pick one DB, and use it fully with all its functionalities !
Pardon my ignorance here, but can't something like an ORM (object relational mapper) work for both SQL and Oracle?
I had similar requirements, to support both Sql Server and Oracle, and summarized my two years of experience with such problems in these articles:
Writing ANSI Standard SQL is not practical.
Think ANSI Standard SQL Is Fully Portable Between Databases? Think Again.

Resources