C # access to Oracle Database

Source: Internet
Author: User

You want to access the Oracle database in C #, after all, it is development and you want lightweight access to Oracle, and you can run the program without having to install an Oracle environment on the client.

Find the relevant information on the Internet, only need to reference a DLL can be implemented.

Access code (reference DLL required):

 Public classOracleconfig {//string connstring = "Data source= (description= (address= (protocol=tcp) (HOST=IP) (port=1521)) (Connect_data= ( (SERVICE_NAME=ORCL))); Persist Security info=true; User Id=system; Password=password; "; Public stringHost {Get;Set; }  Public stringPort {Get;Set; }  Public stringService {Get;Set; }  Public stringID {Get;Set; }  Public stringPassword {Get;Set; } }

 Public classOraclehelper {oracleconfig oracleconfig;        OracleConnection OracleConnection;        OracleDataReader OracleDataReader;        OracleCommand OracleCommand;  PublicOraclehelper (Oracleconfig oracleconfig) { This. Oracleconfig =Oracleconfig; }         PublicOracleDataReader Getdatareader (stringCommandText)            {getoracleconnection (oracleconfig); OracleCommand=Oracleconnection.createcommand (); Oraclecommand.commandtext=CommandText; OracleDataReader=OracleCommand.ExecuteReader (); returnOracleDataReader; }         Public voidCloseConnection () {oracledatareader.close ();            Oracledatareader.dispose ();            Oraclecommand.dispose ();            Oracleconnection.close ();        Oracleconnection.dispose (); }        Private voidgetoracleconnection (Oracleconfig oracleconfig) {OracleConnection=NewOracleConnection (); Oracleconnection.connectionstring=string. Format ("Data source= (description= (address= (protocol=tcp) (host={0) (Port={1})) (Connect_data= (service_name={2})); Persist Security info=true; User id={3}; PASSWORD={4};", Oracleconfig.host,oracleconfig.port,oracleconfig.service,oracleconfig.id,oracleconfig.password);        Oracleconnection.open (); }    }
OracleDataReader OracleDataReader = Oraclehelper.getdatareader ("select * FROM table") ;                      while (Oracledatareader.read ())                    {                       Console.WriteLine (oracledatareader[" field "]. ToString ());} Oraclehelper.closeconnection ();

dll:http://download.csdn.net/detail/lelehellow/9868148

Suzhou Gree Air Conditioning Repair

Suzhou Siemens Refrigerator Maintenance

Shanghai Registered Company

C # access to Oracle Database

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.