Krishnarjun Banoth
Krishnarjun Banoth

Reputation: 1580

Connect oracle database from visual studio 2015

I want to write an web-api with oracle database as my back-end and Dapper as ORM.

I have installed odac.client.x86 and Oracle.ManagedDataAccess and dapper libraries from the nuget package manager. I can able to connect my database from server explorer as shown in below image.enter image description here

Next i had added a Web Api2 empty controller to my project. This is my connection string Source=Oracle_test;Persist Security Info=True;User ID=tams;Password=***********;Unicode=True.

And my code is

   public IHttpActionResult Get()
    {
        using (OracleConnection db = new OracleConnection("Data Source = Oracle_test; Persist Security Info = True; User ID = tams; Password = tams; Unicode = True"))
        {
            db.Open();
            dynamic result = db.Query("Select NAME from APPLICANT_BATCHES").SingleOrDefault();
            return Ok(result);

        }
    }

i am getting exception as TypeInitializationException as shown in below image enter image description here

I am new to dapper and oracle database please help me to connect to my oracle databse and getting results with dapper orm in c#.

My database version is - 11.2.0.1.0 Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

Upvotes: 2

Views: 3884

Answers (1)

Gilles
Gilles

Reputation: 5407

Remove the Unicode = True part in your connection string.

According to the MSDN documentation :

If Unicode is set to true when not using Oracle 9i client software to communicate with an Oracle 9i server, unpredictable results may occur.

Although this is written with an older version of Oracle, I have replicated it with a newer version. I have a project using the Oracle Managed Data Access driver and Dapper to connect to Oracle 11. If I add Unicode = True to my connection strings, it stops working while giving me an exception when creating the new Oracle Connection.

Upvotes: 1

Related Questions