. Net accessing the Oracle database-database connection

Source: Internet
Author: User

. NET and Oracle access, after all, is not a mother-in-law, and sqlserver is a little different.

 

1. namespace selection:

Access the Oracle database through the system. Data. oracleclient, system. Data. oledb, and system. Data. ODBC namespaces. System. Data. oracleclient has the highest access efficiency. system. Data. oracleclient also has the most support for Oracle types. After all, it is customized for Oracle.

 

2. database connection:

Whether it is the kind of machine that needs to run in. Net (ASP. NET is the Web server) to access Oracle, install the Oracle client component. (This is different from the two types of MS databases, MS things install MDAC: Microsoft Data Access Component 2.6 or later, there is no need to install the SQL Server Client or office software, .)

The connection string used to access the Oracle database in system. Data. oracleclient is: "User ID = username; Password = password; Data Source = server ".

In system. Data. oledb, the connection string used to access the Oracle database is: "provider = msdaora.1; user id = user name; Password = password; Data Source = server ".

The connection string used to access the Oracle database in system. Data. ODBC is: "driver = Microsoft ODBC for Oracle; uid = username; Pwd = password; server = server ";

 

3. Data Types in Oracle:
Most of the data types of SQL Server are easy to find close to. net, while the types in Oracle are much different from those in. net.

Number: Number type. Generally, it is number (m, n), M is a valid number, and N is the number of digits after the decimal point (0 by default). This is in decimal format.
Nvarchar2: variable-length Unicode (UNICODE). (The nvarchar2 type is added to orcle8i. Later, Oracle will only support nvarchar2.) (remove "N" from non-Unicode, the same below .)
Nchar: Unicode ).
Nclob: The field used to store a large number of characters (UNICODE.
Date: date type.
In Oracle, fields cannot be of the BIT or bool type. They are generally replaced by number (1.

 

4. Connection sample:

Connect with oracleclient. (for other connections, you only need to change the namespace and connection string)

String oracle_conn = "User ID = userid; Password = ******; Data Source = servername ";
String SQL _search = "select * From table_test ";

Using (oracleconnection conn = new oracleconnection (oracle_conn ))
{
Conn. open ();
Oraclecommand COM = new oraclecommand (SQL _search, Conn );
Oracledatareader DR = com. executereader ();
While (dr. Read ())
{
Response. Write (Dr ["c_name"]. tostring () + "<br> ");
}
Dr. Close ();
Conn. Close ();

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.