C # connects Oracle databases (directly referencing DLLs using-oracle.manageddataaccess.dll)

Source: Internet
Author: User

There is a feature in the project that needs to get data from an Oracle database, and it's a simple thing to replace the original SqlClient with a OracleClient call,

The result is far less simple than you think. There is a lot of need to install Oracle clients, the project is very urgent, the company also does not have Oracle environment, can make me nasty. After searching this area on the Internet,

Too many articles, but also to continue to test, choice, are quickly bored. Finally found a friend of mine, he directly helped me write a demo, I changed the connection string,

I was so grateful to him for the successful connection. This DLL is actually specifically provided by Oracle for C #, and can be downloaded to the official (but cumbersome to find).

Here I will share this program and DLL to everyone.

Action step: DLL download and reference download address: Oracle.ManagedDataAccess.zip After downloading, place the Oracle.ManagedDataAccess.dll in your own project, and then reference
Direct call (connstring to its own connection string)

    A reference to the "Oracle.ManagedDataAccess.dll" class public
        bool Connect (string hostaddress, string servername, String uid is added to the project. string pwd)
        {
            string connstring = ' Data source= (description= (address= (protocol=tcp) (host= "+ hostaddress +") ( port=1521)) (Connect_data= (service_name= "+ servername +"))); Persist Security info=true; User id= "+ uid +"; Password= "+ pwd +"; ";
            OracleConnection conn = new OracleConnection (connstring);
            Conn. Open ();
            IF (Conn. state = = ConnectionState.Open)
            {
                Conn. Close ();
                MessageBox.Show (Conn. State.tostring ());
                return true;
            }
            else
            {return
                false;
            }
        }


Additional Help Documentation:

Http://www.cnblogs.com/yjmyzz/archive/2013/11/01/3400999.html

  http://www.cnblogs.com/ly303550688/archive/2013/01/31/2887104.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.