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-10.2.0.4.zip 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)
)
(CONNECT_DATA =
(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)
{
Try
{
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