. Net implementation code for connecting to the Oracle database

Source: Internet
Author: User
Tags oracleconnection

When accessing Oracle, the client (or web Server) needs to install an Oracle client, which is a bit uncomfortable. SQL Server does not need to be used. MySQL can have at most one MySql. Data. dll. I have been searching for a relatively slim client for a long time, and it is only 12 Mb long and practical. After installation:

A connection and query tool similar to the query analyzer, a configuration file (very important ).

Start the Connection Tool

Enter account information, corresponding to the user id, password, datasource of the connection string


After the connection is successful, you can query it. It looks like a windows program. It looks like a DOS command line tool. after entering the SQL, You have to select "file/Run" to execute the SQL statement.

Configuration file (Configure this file before use), Because it is a lite version, there is no graphical tool configuration, all is Notepad

# DATABASENAME =
# (DESCRIPTION =
# (ADDRESS_LIST =
# (ADDRESS = (PROTOCOL = TCP) (HOST =   127.0 . 0.1 ) (PORT =   1521 ))
#)
# (CONNECT_DATA =
# (SERVICE_NAME = Servicename)
#)
#)

 

Modify the example configuration that has been commented out.

 

MyOracle =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST =   33.33 . 33.33 ) (PORT =   1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = Mysid)
)
)

 

Here, myOracle is a random name, and the data source of the connection string = myOracle; HOST, PORT Needless to say; SERVICE_NAME = mysid fill in the SID of the server database instance, the database is determined here.

After the configuration is complete, you can access Oracle in the program. The following example shows how to obtain the data of a table displayed on the page.

Using System. Data. OracleClient;

OracleConnection con =   New OracleConnection ( " Data Source = myOracle; user id = xxx; password = xxx; " );
OracleCommand cmd =   New OracleCommand ( " Select * from table " , Con );
Con. Open ();
OracleDataReader dr = Cmd. ExecuteReader (CommandBehavior. CloseConnection );
GridView1.DataSource = Dr;
GridView1.DataBind ();
Dr. Close ();

 

-- Displays information about all tables, similar to the show tables command of mysql.
Select   *   From All_tables

-- Display the first few items, similar to SQL Server's select top
Select   *   From Tb WHERE ROWNUM <= 5

-- From table name should be OWNER. TABLE_NAME
Select   *   From Ms. mytable

-- The parameter symbols are different. For oracle: for SQL Server, for @ mysql,?
Select   *   From Tab Where Id = : Myid

Related Article

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.