BadImageFormatException is raised when attempting to load the Oracle client library. This problem occurs if you are running in 64-bit mode with the 32-bit Oracle client component installed.

Source: Internet
Author: User
Tags oracleconnection connectionstrings

Native environment Win10 64-bit system, vs2013 32bit version, Oracle installed on the machine including the server and the client are 64bit

When testing a. NET connection to an Oracle database, there is always the above exception, looking for a number of solutions, such as modifying the Web project platform to x86, or using IIS debugging, and so on, I think is not a solution, and finally found the best solution is as follows:

Download the Instantclient_11_2.zip package, unzip it, and place it anywhere else in the Oracle installation path.

In the environment variable path of the system, the path of the oracleinstantclient is set before the path of Oracle, which is the difference between the installation version and the press release (System variable), which will D:\app\instantclient_ 11_2 is placed in front of the Oracle path in path, which perfectly solves

Note: The path set in path must be placed in front of the Oracle path, remember to modify the Instantclient_11_2 folder E:\app\instantclient_11_2\network\ADMIN\tnsnames.ora Configuration information inside the file

Tnsnames.ora file:

1 # TNSNames. ORA Network Configuration File:c:\oracle\ora90\network\admin\tnsnames.ora2 # Generated by Oracle configuration tools.3 4 #sample5 6#DATABASENAME =7# (DESCRIPTION =8# (Address_list =9# (ADDRESS = (PROTOCOL = TCP) (HOST =127.0.0.1) (PORT =1521))Ten #    ) One# (Connect_data = A# (service_name =servicename) - #    ) - #  ) the  -Orcl= -(DESCRIPTION = -(Address_list = +(ADDRESS = (PROTOCOL = TCP) (HOST = localhost) (PORT =1521)) -     ) +(Connect_data = A(service_name =ORCL) at     ) -)

The test code is as follows:  

1      Public classSqlHelper2     {3         Private Static stringConnStr = system.configuration.configurationmanager.connectionstrings["ConnStr"]. ToString ();4          Public StaticDataTable Query (stringsql)5         {6DataTable dt =NewDataTable ();7             using(OracleConnection conn =NewOracleConnection (connstr))8             {9 Conn. Open ();TenOracleCommand cmd =NewOracleCommand (sql,conn); OneOracleDataAdapter adapter =NewOracleDataAdapter (cmd); A adapter. Fill (DT); -                 returnDT; -             } the         } -}

Configuration file Config

1<configuration>2<connectionStrings>3<add name="ConnStr"connectionstring="Data source= (DESCRIPTION = (Address_list = (ADDRESS = (PROTOCOL = TCP)
(HOST = localhost) (PORT =1521))) (Connect_data = (service_name =orcl))); user=***; password=******;
Persist Security Info=false; Min Pool size=10; Max Pool size=100; Pooling=true;"/>
<!--<add name= "connstr" connectionstring= "Data source= (description= (address_list= (address=)
(Host=localhost) (port=1521))) (Connect_data= (SERVICE_NAME=ORCL))); User id=***; password=***; " />-->4</connectionStrings>5<system.web>6<compilation debug="true"targetframework="4.5"/>7"4.5"/>8</system.web>9 Ten</configuration>

BadImageFormatException is raised when attempting to load the Oracle client library. This problem occurs if you are running in 64-bit mode with the 32-bit Oracle client component installed.

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.