I want to connect from asp.net to oracle client 11g .I downloaded and setup ODAC 32 bit from this link .I added reference to Oracle.data.access.dll
in Visual studio 2012.When I execute my web program I encountered the same error.
Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. Geçersiz biçimdeki bir program yüklenmek istendi.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
And my code :
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Odbc;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Data;
namespace OracleDbConnection
{
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string oradb = "Data Source=(DESCRIPTION="
+ "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-XX)(PORT=1521)))"
+ "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));"
+ "User Id=G;Password=G;";
OracleConnection conn = new OracleConnection(oradb);
try
{
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select dname from dept where deptno = 10";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
}
catch (Exception ee)
{
ee.ToString();
throw;
}
}
}
}
You have not specified the location of the Oracle database and version.
Installed on the same workstation/server as the IIS and VS 2012?
Installed on a remote workstation/server in an intranet environment?
If local, Oracle advises creating a Microsoft Loopback Adapter virtual LAN with STATIC IP, disabling temporarily all other network devices, and installing Oracle on the Loopback adapter static IP, and then enabling other network devices. Details in the
Oracle Windows Installation Guide.
If remote, how can you resolve the Win-XX host name?? It is better to use the static IP address of the database server for the host name.
If remote, software and hardware firewall must allow traffic on port 1521.
I use Oracle Client 11g.I connect to Oracle server with specific ip range. I used same tnsnames(includes host=Wın-XX) for connect to db from sql developer so I succesfully connected the db.I installed the
this ODAC version.
Additionally I used the dll under the C:\Windows\Microsoft.NET\assembly\GAC_32\Oracle.DataAccess .Problem solved.but I dont understand why.
What is the oracle.access.data.dll difference between the C:\Windows\Microsoft.NET\assembly\GAC_32\Oracle.DataAccess and D:\app\product\11.2.0\client_6\odp.net\bin\4 ?
fr3d
Member
8 Points
36 Posts
Asp.net Oracle 11g client problem
Dec 23, 2012 09:26 PM|LINK
Hi,
I want to connect from asp.net to oracle client 11g .I downloaded and setup ODAC 32 bit from this link .I added reference to Oracle.data.access.dll in Visual studio 2012.When I execute my web program I encountered the same error.
And my code :
using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Odbc; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; using System.Data; namespace OracleDbConnection { public partial class Home : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string oradb = "Data Source=(DESCRIPTION=" + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-XX)(PORT=1521)))" + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));" + "User Id=G;Password=G;"; OracleConnection conn = new OracleConnection(oradb); try { conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "select dname from dept where deptno = 10"; cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); dr.Read(); } catch (Exception ee) { ee.ToString(); throw; } } } }How can I solve this problem?Any suggestions?
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Asp.net Oracle 11g client problem
Dec 23, 2012 10:43 PM|LINK
do you have an x64 pc?
fr3d
Member
8 Points
36 Posts
Re: Asp.net Oracle 11g client problem
Dec 23, 2012 11:09 PM|LINK
I have win 7 64bit pc and Visual studio 2012 64 bit.
ignatandrei
All-Star
135142 Points
21676 Posts
Moderator
MVP
Re: Asp.net Oracle 11g client problem
Dec 24, 2012 06:50 AM|LINK
somewhere in the application pool properties you can configure to load 32 bit dlls.
fr3d
Member
8 Points
36 Posts
Re: Asp.net Oracle 11g client problem
Dec 24, 2012 08:20 AM|LINK
I configured the IIS application pool like this .But nothing changed.I encounter same error.
Lannie
Contributor
3738 Points
728 Posts
Re: Asp.net Oracle 11g client problem
Dec 25, 2012 03:18 AM|LINK
You have not specified the location of the Oracle database and version.
Installed on the same workstation/server as the IIS and VS 2012?
Installed on a remote workstation/server in an intranet environment?
If local, Oracle advises creating a Microsoft Loopback Adapter virtual LAN with STATIC IP, disabling temporarily all other network devices, and installing Oracle on the Loopback adapter static IP, and then enabling other network devices. Details in the Oracle Windows Installation Guide.
If remote, how can you resolve the Win-XX host name?? It is better to use the static IP address of the database server for the host name.
If remote, software and hardware firewall must allow traffic on port 1521.
What version of ODAC was installed?
fr3d
Member
8 Points
36 Posts
Re: Asp.net Oracle 11g client problem
Dec 25, 2012 05:18 PM|LINK
I use Oracle Client 11g.I connect to Oracle server with specific ip range. I used same tnsnames(includes host=Wın-XX) for connect to db from sql developer so I succesfully connected the db.I installed the this ODAC version.
Additionally I used the dll under the C:\Windows\Microsoft.NET\assembly\GAC_32\Oracle.DataAccess .Problem solved.but I dont understand why.
What is the oracle.access.data.dll difference between the C:\Windows\Microsoft.NET\assembly\GAC_32\Oracle.DataAccess and D:\app\product\11.2.0\client_6\odp.net\bin\4 ?
Lannie
Contributor
3738 Points
728 Posts
Re: Asp.net Oracle 11g client problem
Dec 25, 2012 11:18 PM|LINK
I always put D:\app\product\11.2.0\client_6\odp.net\bin\4 ODAC dll directly in the project /BIN folder and make a local reference to it.
I just have had way less problems doing it this way, especially when moving from dev to test to production servers bypassing the GAC completely.