C # connect to the Oracle10g Database without installing the Oracle10g Client

Source: Internet
Author: User
Tags oracleconnection

The latest project must be written as a fromProgramAnd all data operations are related to Oracle...
This is exhausting. As we all know, the local machine does not have the Oracle client installed, and the local program cannot access the Oracle database.
However, a client must have at least 80 Mb. It's too big. It is inconvenient to deploy the program.
I found a solution on the Internet. Ecstasy... not long... The final confirmation is not very useful...
Finally, with the joint efforts of the Internet and colleagues. Finally, the test is successful ..
The method is as follows: (Environment: vs2003 + Oracle10g)

1. Extract the files in instantclient-basic-win32- to the specified location (I decompress the files to D: \ Fox and name them instantclient)
The content should include nine files: basic_readme, OCI. dll, ocijdbc10.dll, ociw32.dll, orannzsbb10.dll, oraocci10.dll, oraociei10.dll, classes12.jar, and ojdbc14.jar.
(Note: accept)

2. Add the tnsnames. ora file (to the D: \ Fox \ instantclient file ):
The content of the tnsnames. ora file:
# Tnsnames. ora network configuration file: D: \ Fox \ instantclient \ tnsnames. ora/* This is the file address */
# Generated by Oracle configuration tools.

Orcl1 =/* This is the service name of the local Oracle server,CodeUsed in */
(Description =
(Address_list =
(Address = (Protocol = TCP) (host = server address IP address or server name) (Port = server port number, "1521" by default)
(SERVICE_NAME = Name of the server database service. Default Value: "orcl")

3. Add the Registry content: (the content is as follows. Change the file location as needed)

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ environment]
"LD_LIBRARY_PATH" = "d :\\ Fox \ instantclient"
"Tns_admin" = "d :\\ Fox \ instantclient"
"Nls_lang" = "american_america.zhs16gbk"

4. Add Environment Variables

Right-click "my computer"> "properties"> "advanced"> "environment variables"> "system variables"> select "path"> "edit" --> Add "after" variable value "original data "; d: \ Fox \ instantclient"

5. restart the computer (in this Order, it is not necessary to restart the computer ).

6. query some codes of the Oracle database:

Of course, the basis for running this code: In this development project --> Add reference -->. Net tab, select system. Data. oracleclient. dll.
Add using system. Data. oracleclient at the beginning of this Cs; // reference the Oracle connection class

Private void button8_click (Object sender, system. eventargs E)
Oracleconnection CNN = new oracleconnection ("Data Source = orcl1; user id = solution name; Password = password ");
CNN. open ();
Oracledataadapter myda = new oracledataadapter ();
Myda. selectcommand = new oraclecommand ("select * From \" table name \ "", CNN); // when querying, the table name is enclosed in double quotation marks.
Dataset myds = new dataset ();
Myda. Fill (myds );
This. textbox1.text = myds. Tables [0]. Rows [0] [0]. tostring (); // obtain the first column of the first row of the query table
Catch (exception ex)
MessageBox. Show (ex. Message );
The above is my solution to connect to the Oracle database without installing the Oracle client.
For more concise information, leave a message ..

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/lhg0302/archive/2009/04/11/4062569.aspx

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.