Click here to Skip to main content
15,561,290 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I am trying to create an application with ODBC compliant code for DB

business logic is in c#

DBs to use are oracle 12c and 11g and MSSQL

I am using

ADO.NET, OLEDB, ODP.NET , ODBC etc.

Problem is when i try to use the ODBC code with oracle 12C where i am getting cast errors and other errors,

I have tried

IDbConeection, IDbCommand etc but they have a problem in case of Oracle (Ref Cursor) and data types of different databases and also there is problem with the DBTypes

because they are enum define differently with different data providers.

for example,
for boolean, the links below show i can use SQL_BIT as ODBC type but it's not even

showing up in the intellisense


to achieve this?https://docs.oracle.com/cd/E15817_01/server.111/e10311/apa.htm

https://docs.oracle.com/cd/B19306_01/server.102/b14232/apb.htm



Can I use the same code against the Oracle database, without code change?

Because some of the datatypes in Oracle and SQL Server are quite different, and code also throws error.

Is there any way to achieve this? Some link or guide would be appreciated.

What I have tried:

here is below example it is working in MSSQL but its not working with oracle database . it gives me invid datatype error of boolean.

string strQuery = "SELECT remember_me, forgot_password, throttle_auth, maximum_attempts, company_name FROM tbl_settings";
                var ds = dbManager.GetDataSet(strQuery, CommandType.Text,null);
               ds = DataControl.GetDataSet(strQuery);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (bool.Parse(ds.Tables[0].Rows[0]["remember_me"].ToString()) == true)
                    {
                        divRememberMe.Visible = true;
                        rememberMe = true;
                    }
                    else
                    {
                        divRememberMe.Visible = false;
                        rememberMe = false;
                    }
                 }
Posted
Updated 8-May-20 20:19pm
v2
Comments
Anurag Gandhi 8-May-20 22:48pm    
I suggest to use ORM or Micro ORM like EntityFramework or Dapper for Database communication. That way you can avoid hand written query and your ORM tool will take care of query syntax.

1 solution

Take a look at Best-orms-for-c[^]

And this CodeProject article: VITA – A Powerful and Flexible ORM and Additional Building Blocks for .NET Applications[^]

If you don't want to use an ORM, take a look at: Don't Hard Code Your DataProviders[^]
 
Share this answer
 
v2

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