Click here to Skip to main content
15,850,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am looking to build an application that is able to connect to any database.
Assuming of course that I know the corresponding IP Addresses, user name and passwords.

Is there anyway that I can do this?
Without obtaining DLLs specific to a database type?

What I have tried:

I am looking at documentation for ODBC but thus far they seem to point to me editing the ODBC Data sources on the computer which I am trying to avoid.
Posted
Updated 15-Jan-19 3:24am
Comments
Maciej Los 15-Jan-19 3:40am    
What about ADO.NET OledDb?
amsga 15-Jan-19 3:43am    
Never tried that before. I'll go read up a bit on that. Thanks.

Not really. Even if you use OleDb, it needs the correct DB engine to be installed on the machine (which means the DLL files need to be there).

The only way to avoid needing "external" assemblies of some form would be to write your own code to interface to each type of system - which is a massive job, and probably one that would never get finished (since features get added or changed in DB's all the time).

Why would you want to avoid adding DLLs to a computer, if they are needed by your app when the user installs it? You may have to install .NET anyway (or your C# code can't run) so what's the problem with the DLL dependencies at the same time?
 
Share this answer
 
Comments
amsga 15-Jan-19 4:12am    
I was wondering if there was an All-In-One in a sense to connect, so that I can avoid writing duplicate codes for each type.
OriginalGriff 15-Jan-19 4:27am    
Provided you stick to "basic" SQL commands, and don't try anything fancy, you *might* get away with it, by issuing the same SQL commands to a generic interface which selects which system type to connect to. But ... even then it's probably going to have problems with some systems, because (for example) parameterised queries - which you DO need to use at all times - aren't handled exactly the same by all systems. Some want named parameters, others are happy with '?' and order-based parameters. Some DB's support Stored Procedures, others don't. And there are big differences in the syntax once you move away from vanilla "SELECT * FROM MyTable" so you will need to know exactly what you are doing and may not get efficient queries to run at all. You may be able to get your generic interface to translate your SQL, but then you're back to having to write code specific to each system you might connect to.

I think I see why you'd want to do that, but ... it's going to be a PITA to keep it maintained! (It's bad enough having to deal with two different versions of SQL Server, let alone get the top 10 rows only from MsSQL and MySQL ...)
I truly believe that a... "Universal Database Provider" does not exists, even if DevArt[^] states that has got it.

In my opinion, there's no chance to build an application, which is able to connect to any database, without third party providers:
- Firebird: .NET Provider[^],
- Oracle Data Provider for .NET (ODP.NET)[^] (Microsoft recommends to use a third-party Oracle provider, due to the types in System.Data.OracleClient will be removed in the future),
- MySQL Connector/NET[^],
- Npgsql - .NET Access to PostgreSQL | Npgsql Documentation[^],
- etc.
There's so many different database systems... Please, visit a: ConnectionStrings.com[^] site to find out.
 
Share this answer
 
v2
Comments
jsc42 15-Jan-19 4:17am    
Even if you can connect, you must be aware that there are many SQL Dialects and versions; so you would have to code variants for different systems.
Maciej Los 15-Jan-19 4:32am    
Good point!
You might also be interested in using an ORM which allows to program database independent, see here: Which is the "best" data access framework/approach for C# and .NET? - Stack Overflow[^]
I tried NHibernate, but would not recommend it as the learning curve is very steep.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900