I'm relatively new to .NET but I'm trying to determine if it's possible to have a single .NET 4 application connect to multiple vendor databases simultaneously (SQL Server, Oracle, DB2 and MySQL) using ADO.NET and execute queries simultaneously?
All the examples I've found so far talk about connecting to only one database at a time.
Thanks!
You just need 4 connections strings and 4 separate ADO Connection objects. And then what SLaks said about async queries to do them simultaneously, if you truly want them running in parallel.
You can execute two queries the same way you execute one query.
If you want them to execute two queries at once, you'll need to make asynchronous queries or use threads.
The ADO.NET framework defines an abstract set of 'DbXXX' classes like DbConnection,DbCommand etc, which are implemented by various database providers such as
System.Data.SqlClient.SqlConnection' in the System.Data.dll for Sql Server
'Oracle.DataAccess.Client.OracleConnection' in the Oracle.DataAccess.dll (ODP.NET provider) for Oracle
'MySql.Data.MySqlClient.MySqlConnection' in the MySql.Data.dll for MySql etc
You then need to design your apllication against the abstract set of classes and use appropriate implementations wherever required. Most of the queries should work against all the backends but there will obviously be backend specific tweaks, not to mention stored procedure calls.
Alternatively you could use an ORM (Entity Framework, Telerik OpenAccess ORM, NHibernate etc) and abstract much of this difference to the ORM. Although I am not sure you can use a single entity model (in EF) against multiple backends.
Related
I have 2 different SQL Server databases which cannot be combined as one of them is a vendor db. Aside from creating a view in SQL server with linked databases, is there a way to use fluent api or something in entity framework to perform simple joins between tables between the two databases?
Apparently this will is how its done.
http://www.c-sharpcorner.com/UploadFile/ee01e6/how-to-join-two-tables-from-different-database-using-entity/
I'm writing an application that should be able to query different databases from different vendors (Oracle, Sybase, SQL Server, MS Access).
Is there any tool that performs this for C# or VB.Net ? something like UnityJDBC ?
I would like to avoid creating different interfaces that communicate with different SQL structures to query databases.
Thanks
Nothing is built into .NET out of the box. However, simple web searches proves that it is possible to use LINQ to all of these
Oracle: http://download.oracle.com/oll/obe/EntityFrameworkOBE/EntityFrameworkOBE.htm
Sybase: http://www.sybase.com/detail?id=1056609
Access: http://forums.asp.net/t/1542443.aspx
SQL Server (there are a lot of resources, here's a comprehensive one): http://www.codeproject.com/Articles/215712/LINQ-to-SQL-Basic-Concepts-and-Features
We have an application that requires our customers to have a SQL server instance on site. At their request, the application needs to synchronize the data in their database with a copy in our datacenter.
We're using .Net 3.5 SP1. We need to synchronize the data exactly, including IDENTITY columns.
We'd prefer to use something like LINQ to SQL that would let us make some simple select and insert/update calls against mapped entities. However, the IDENTITY columns seem to be a problem with LINQ and similar approaches.
We can do this all with built-up SQL statements and turn IDENTITY INSERT on / off as needed, but I'd prefer a more elegant solution.
Thanks!
** Edit - We DO need to write our own solution, and we do need to use .Net 3.5 SP1 to do it. I won't spend your time explaining all the reasons why, but please limit suggestions to options within the .Net playground.
Microsoft Sync Framework can be your solution. This is framework description from Microsoft:
Microsoft Sync Framework is a data synchronization platform from Microsoft that can be used to synchronize data across multiple data stores. Sync Framework includes a transport-agnostic architecture, into which data store-specific synchronization providers, modelled on the ADO.NET data provider API, can be plugged in.
Sync Framework is a comprehensive data synchronization solution that enables developers to build solutions that support synchronization of any database, on any data protocol over any network topology. msdn.microsoft.com
For your convinience providing link to good tutorial on the subject
If it is just a couple of tables that need to be synchronized and there is not a lot of data in the tables (now and future) you could develop some sort of bulk copy from your servers and bulk insert routine on the customer's server.
Since you said you can't use SQL Server replication services or SSIS, then perhaps a backup/restore procedure could be written. You could take a scheduled backup of your database and make it available to calling applications which could then copy the backup, restore it to another instance on the customers server, then pull all data you need via any number of methods and it would exist locally on the customers servers.
Beyond that, I think you may be asking for a maintenance and synchronization nightmare if you can't base your solution on tools that are made to do this sort of thing.
What strategies and techniques have you used to produce a data driven application that needs to access multiple diverse data sources? Specifically, Microsoft Access and SQL Server. Ideally, I'd like to make an abstraction layer that hides the physical data source from the application.
Something like the ADO.NET Entity Framework would be ideal, but it doesn't have an MS Access provider. Is there a different framework or technique that supports simultaneous Access and SQL Server connections?
How much work would it be to make an Access provider for the Entity Framework?
I'm pretty sure LLBLGen supports Access (and, of course, it supports MS SQL). It costs money though, but IMHO it's the best OR/M for .NET.
Another approach is to create Linked Servers in SQL Server, perform joins using views in SQL Server and completely hide the fact there are multiple data sources from your application.
As far as I know, there are only two choices:
Multiple connection strings
Single connection string.
In the first scenario, you join any data you need from the disparate sources in the middle tier code. In the second scenario, you access all sources but one indirectly through the one source. For example, you'd retrieve data from Access via a Linked Server in SQL Server.
They each have their advantages and disadvantages. Using a single connection string is certainly simpler to code against in the middle-tier. Ultimately it depends on the need of two sources. If one is simply for logging for example, then two connection strings might be simpler. If joins and such are needed, then using a linked server might be easier depending on the sources. If one of the sources is Access and you are not using Access security, then using a Linked Server can work fine depending scale. If you are using Access security and have different logins that need to access the database, then using a linked server will be a pain.
Look at NHibernate. It has providers for SQL Server and Access (and others).
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.