C # System.Data.OracleClient requires Oracle client software 8.1.7 or later

Source: Internet
Author: User

A few days ago, the situation was encountered when connecting with the Oracle database. The client is already installed on the machine, and the Toad Database tool can be used to connect to the database for related operations. However, this problem occurs when you use code to connect. Looking for a long time, have not found the reason, finally a colleague of mine to find, he directly to the code in a paragraph commented out, the results of the program can be run, is really admire. But we don't really know why, so I decided to find out.

First on the network to find a lot of answers to this question, but none can meet our situation, so you may encounter problems are the same as the problem we encountered, but may be different yo. If you encounter the same problem, I am glad to be able to help you.

All right, the nonsense is not much to say, first to solve the problem of the summary. You can do this for the time being,

1. Check whether the compilation environment is compliant, and the platform settings, generally changed to X86 (this is my other colleague's computer problem, also has the problem, has changed to be good) 2. See if there is a code similar to this in code (C #): String oraclepath = System.windo Ws. Forms.Application.StartupPath;
Environment.setenvironmentvariable ("PATH", oraclepath,environmentvariabletarget.process);  This code needs to be commented out or seen in the following way. 3. Reload the client to see if the problem is resolved (this is possible the environment variable path is not configured well)

4. Others have not yet been found

The whole question my solution: if there is anything wrong, please be sure to point out, thank you.

Description: The following method is based on the problem that we know should be the following statement.

1 , problem analysis :

In the execution environment.setenvironmentvariable ("path", Oraclepath, environmentvariabletarget.process), before this sentence the value of the environment variable PATH is as follows:

C:\oraclexe\app\oracle\product\10.2.0\server\bin;
C:\oracle\product\10.2.0\client_1\bin;
C:\Oracle\Ora81\bin;
C:\Program Files\oracle\jre\1.1.7\bin;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Program Files\Common Files\autodesk shared\;
C:\Program Files\Microsoft SQL Server\90\tools\binn\

After executing the above statement, the value of the environment variable path is

E:\words\ sample code \ Weekly work report customer Dcclient-cs\workcollector\bin\debug

The above values are missing. Then there is the problem. Deleting the statement does not show the above problem. There is no doubt that the setting of the environment variable caused the problem to occur.

2 , Reason:

. NET connection Oracle uses the OCI interface, the Oracle client must be installed, and the local network service name Tnsnames.ora is configured. After we have installed the client, the software will be configured for us accordingly. The environment variable is added for us when we configure it. The above setting causes the environment variable to be lost when the program is running, which affects the operation of the Oracle client. In order to verify the above idea, I carried out the experimental verification.
3, Experiment:
Effect of environment variables on client operation
A. First, the PATH environment variable in the computer about the Oracle client registration cleanup, restart the computer for environment variables to take effect
B. Run the program that commented out the above environment variable setting, the program that should run correctly has the same error as before
C. Then I will add the environment variable path of the Oracle client to the current executable path as a string, set by the statement setting the environment variable above.
D. Run the program again and the program runs correctly.
Experimental Analysis: Explains the setting of the environment variable is the cause of the error
4, the purpose of the program to write this statement is analyzed:The possible purpose is to make the current program run under the full control of the operating system, to join the system when it is required to run a program without telling it the full path of the program, in addition to the current directory in the search for this program, but also to the path specified in the paths to find.user by setting environment variables, to better run the process (Baidu said)。
5, Workaround:
One is to keep the full path of the current program, and the other is not reserved.
The first type:
A. Add through configuration to add the full path of the current program to the environment variable
B. Adding through a program
1. Take out the full path of the current program run:

String Oraclepath =system.windows.forms.application.startuppath
2. Remove the current environment variable (PATH):

String str = environment.getenvironmentvariable ("PATH");
3, through the string connection, the environment variable is reset: Environment.setenvironmentvariable ("PATH", oraclepath+ ";" + str, environmentvariabletarget.process);

The second way: The full path of the program is not added directly to the environment variable path, that is, the course search path to add the program.
6. Summary
Add the full path of the program's executable to the environment variable path can increase the stability of the program, especially in the production release version, you can prevent the failure to find executable files, after all, the computer sometimes error, this is only a double-insurance feeling.

Well, basically that's what I do, and if there are better, we can discuss together and learn together.

  

C # System.Data.OracleClient requires Oracle client software 8.1.7 or later

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.