The advantages of this method: 1, the integration of Oracle client within the program, no need to configure users themselves
The disadvantage of this method: 2, increase the volume of the package (Oracle Instant client itself has a few 10 megabytes size)
Here's how it's implemented.
If you have a TNS name to access the Oracle database, do the following.
- A. Add Tnsnames.ora to the program's Oracle folder and write the name of TNS into the inside.
- B. Where the program sets environment variables, add
Environment.SetEnvironmentVariable("TNS_ADMIN", oraclePath,EnvironmentVariableTarget.Process);
- C. The TNS name should be available in the connection string
The overall code is as follows:
//This sentence gets the location of the Oracle Drive folder, which is where oci.dll is placed. stringOraclepath = System.Windows.Forms.Application.StartupPath +@"\orclconn"; // //This sentence sets the environment variable "PATH", written to the folder where the Oracle driver resides,// //The third parameter indicates that this path only works in the current process and does not modify the computer itself. // //Note: If you use some external programs, there are other path variables to set up, join here. See. NET related documentation for specific methods. ///when the system also uses the environment variables of other software, it needs to get the environment of the native computer and use it together with the Oracle environment variable. strings = environment.getenvironmentvariable ("PATH", Environmentvariabletarget.machine); Environment.setenvironmentvariable ("PATH", S +";"+Oraclepath, environmentvariabletarget.process); // //this sentence, set the language and character set that Oracle uses in the communication processEnvironment.setenvironmentvariable ("Nls_lang","simplified Chinese_china. ZHS16GBK", environmentvariabletarget.process); // //add Tnsnames.ora to the program's Oracle folder and write the name of TNS in the inside. // //B. Where the program sets environment variables C. The TNS name should be available in the connection stringenvironment.setenvironmentvariable ("Tns_admin", Oraclepath, environmentvariabletarget.process);
In C #, do not install Oracle clients how to connect to an Oracle database