Four ways to connect to a database in C # (GO)

Source: Internet
Author: User

Four ways to connect to a database in C #

Before you connect to the following database, install the Oracle Client locally, and the version of this test System.Data is: 2.0.0.0.

On the installation of Oracle client please note that if the OS is 3-bit Please install the Oracle client-bit , but the OS is-bitand needs to be installed according to the actual situation, If your app is running according to-bit , you need to install the-bit client, if it is 64-bit run, install 64-bit client, not the OS is-bit , The 64-bit Oracle client will be installed.

This test will be tested at the same time on the-bit and-bit , with a-bit oracle10g.

1.ODBC

1.1 first needs to be in Control Panel, management tools, data Source (ODBC).

1 . 2 using System.Data.Odbc;

1.3 Connection Database

OdbcConnection conn = new OdbcConnection (dsn=xxx; Uid=XXX; pwd=XXX;);
Conn. Open ();
Conn. Close ();      

-bit and-bit are OK.

2.OleDb

      2.1   OLE DB connection driver msdaora and OraOLEDB.Oracle, respectively, by Microsoft and oracle. use OraOLEDB.Oracle drive Oracle Data provider for OLE DB. Both on 32-bit machines, on 64-bit machines, using "msdaora" will appear " The "msdaora.1" provider "problem is not registered on the local computer, OraOLEDB.Oracle everything is fine.

2.2 Connection Database

Using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection ("Provider=MSDAORA.1; User id=xxx;password=xxx;data source=XXX;  Persist Security info=false "); Provider need to change according to the actual situation
Conn. Open ();
Conn. Close ();

3.OracleClient

3.1 //using System.Data.OracleClient;

3.2 connecting to a database

OracleConnection conn = new OracleConnection ("Data source=xxx;user=xxx;password=XXX;");
Conn. Open ();
Conn. Close ();

-bit and 64-bit are OK.

4.OracleDataAccess

4.1//using Oracle.DataAccess.Client need to install Oracle Data providerfor. NET Framework 2

4.2 Connection Database

Oracle.DataAccess.Client.OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection ("Data source=yellow; User id=knemes; Password=oracle ");
Conn. Open ();
Conn. Close ();

-bit and 64-bit are OK, but you need to pay attention to your version

Four ways to connect to a database in C # (GO)

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.