This question similar to link
link2
I fixed this problem, but when I opened new project Wcf service library, I had that same problem, and all this changes that I had done before did't help me.
I tried every thing that I did before and even more but it didn't helped.
It is important to say that if I do the same in another project all work fine but in WcfServiceLibrary it doesn't work.In WcfServiceApplication it working too.
I use VS2012(4.5) Win7 (64), my Oracle clien 32, but in other project this is not a problem.
Maybe it because Wcf library project i don't know.
i just buil service that save datd from database and i get error on connection to db.
Error: Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.
My code
using (OracleConnection con = new OracleConnection())
{
con.ConnectionString = "User Id=zxc;Password=zxc;Data Source=NXE";
con.Open();//here i get error
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "select * from " + Table;
int rowsUpdated = cmd.ExecuteNonQuery();
OracleDataReader reader = cmd.ExecuteReader();
String DataFromORL = "";
int row = 0;
while (reader.Read() && row < 50)
{
row++;
if (reader.HasRows)
{
DataFromORL += reader.GetInt32(0);
}
}
}
I too got the same issue.
for me issue got fixed by doing the following thing.
prior to this check whether you have installed both 32bit and 64bit Oracle clients to make it available in both environments.
for me the reason for getting this error.
Error: Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64-bit mode with the 32-bit Oracle client components installed.
is because of the environmental variables has only one installation location and it is 32bit installation location that's why the error is This problem will occur when running in 64-bit mode with the 32-bit Oracle client components installed.
so, to resolve this what I did is, I added 64-bit installation location also and restarted my visual studio. if it does not work try by restarting system also, we are supposed to add both bin directories available in Oracle client installation location that we specify while installing Oracle clients. In my system location is like: 32-bit C:\app\client\<user>\product\12.1.0\client_2\bin
64-bit C:\app\client\<user>\product\12.1.0\client_1\bin
Related
First lets mention that I am working on some program that is already using a database from our other program which I haven't built.
So I tried to use stored procedure and here is how that procedure looks like:
↑OK
↓VRDOK
↓BRDOK
↓ROBAID
↓CENA_BEZ_PDV
↓KOL
↓RABAT
So here is my commmand:
using (var command = new FbCommand("NAPRAVISTAVKU", con)
{
CommandType = CommandType.StoredProcedure
})
{
command.Parameters.AddWithValue("#VRDOK", 33);
command.Parameters.AddWithValue("#BRDOK", 711066);
command.Parameters.AddWithValue("#ROBAID", 1040);
command.Parameters.AddWithValue("#CENA_BEZ_PDV", 0.0);
command.Parameters.AddWithValue("#KOL", 10.0);
command.Parameters.AddWithValue("#RABAT", 0.0);
FbDataReader dr = command.ExecuteReader();
while (dr.Read())
{
MessageBox.Show(dr[0].ToString());
}
}
So my question is why am I getting this error that funcion rounddec is not defined. Is that function supposed to be in database or in my program or other external file? Is there a way to create new function inside my program and call it ROUNDDEC since I know what it needs to do?
Error image link
ROUNDDEC is part of FreeUDBLib.dll and it is working with 32bit firebird. Problem was I had installed on my PC Firebird 3.0 x64, Firebird 2.1 x64 and Firebird 2.1 x86. My program was built to work for Firebird 2.1 x86, but for some reason, even if I had this DLL in x86 version ULF file, it was not pulling it from it, instead it was checking for UDFs in x64bit version. So solution was to uninstall all versions and reinstall 2.1 x86, then reinstall ddex and firebird.sql and it worked.
I think there is better way to manually set up folder for UDF, but for now I do not know so this was the acceptable solution.
I have a ASP.NET MVC application (64bits) running in a 64 bits Windows system (Windows Server 2012).
My web application needs to read a mdb database, then I created the next code:
using (var myConnection = new OdbcConnection())
{
try
{
string myConnectionString = #"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + fileNameWithPath + ";Persist Security Info=True";
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
OdbcCommand cmd = myConnection.CreateCommand();
cmd.CommandText = "SELECT * FROM myTable";
OdbcDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
// Load the result into a DataTable
myDataTable = new DataTable();
myDataTable.Load(reader);
}
catch (Exception exception)
{
//nexy exception is caught here: "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
}
finally
{
myConnection.Close();
}
}
Where fileNameWithPath is the path of the mdb file.
When I execute the code above, I have the next annoying exception in the line
myConnection.Open();:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified
I've checked the server and it has the next files installed regarding ODBC driver:
File odbcad32.exe under the folder C:\Windows\System32
File odbcad32.exe under the folder C:\Windows\SysWOW64
My question is: Is my server setup correct? Do I have the 64 bits version of ODBC really installed?
and more important: Can I run a x64 application in x64 server with such configuration? Otherwise, is there any other alternative? It is worth to mention that:
I'm not allowed to install additional software in the server
The web application must be 64 bits
Thanks in advance.
To use the x32 bit version of the Access database engine, then you will require an x32 bit version of the database engine installed on that computer.
And to use the x64 bit version of the Access database engine, then you require an x64 bit version of the Access database engine to be installed.
And hey, if you need to read an oracle database, then lo and behold, you need the oracle database engine installed to read oracle files that reside on the disk drive.
If you can’t install any additional software such as oracle to read oracle files, or SQL server to read sql server files, or in this case Access, then you are duck soap. And really, to read PDF files, then you need some PDF file software installed.
So unless you can get around the issue of not being allowed to install the appropriate software on your server, then you not going to be able to read the given files that such software consumes – this applies to near EVERY software system - you need to install the appropriate software on that server to enable use of such files.
So there does exist both an x32 and x64 bit version of the Access database engine (ACE), and unless you are allowed to install such software then you can’t read and consume such data.
So keep in mind that when developing software, if you want to open a word file, or pdf file or like any software system you will require the apocopate software to be installed to work with such files – Access is no exception. If you need to open a power point file, then it becomes obvious that you need power point software installed on that computer.
So you need to obtain and install the x64 bit version of the Access database engine on that server. And since you note you can’t install any software, then you are unlikely to achieve your goal.
I resolved a very similar issue by enabling 32-bit applications in the advance settings of the application pool in IIS
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
I know the common fix for this which is to install:
Microsoft Access Database Engine 2010 Redistributable
Or
2007 Office System Driver: Data Connectivity Components
Both are installed on my local PC. This is the code which I have
OleDbConnection conn = new OleDbConnection();
string fileName = "test.xlsx";
try
{
string connectString = String.Format(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR={1};'",
fileName, "YES");
conn.ConnectionString = connectString;
conn.Open(); //exception is thrown here !!!
OleDbCommand comm = new OleDbCommand();
comm.CommandText =
string.Format("CREATE TABLE [{0}] ", "Test");
comm.Connection = conn;
comm.ExecuteNonQuery();
OleDbDataAdapter ad = new OleDbDataAdapter(
string.Format("SELECT * FROM [{0}]", "Test"), conn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(ad);
}
catch(Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
I try this code in other projects on my local machine and everything is working. I have project which creates excel exports and I don't have this problem.
The problem is in the project I don't understand how to fix it. Also on the current project I create one new .aspx page and in Page_Load put only this code, same exception.
Additional information: this project was written on vs 2008, convert to 2010 and after that used in vs 2012. Everything was working in the project till now.
Also same thing for JET connection string !
EDIT
After the answer of Joe I see that this project is run on 64bitProcess:
bool test = Environment.Is64BitProcess; //return true.
My driver is for 32bit. What I can do now, can I change the environment process. I can't install the driver for 64bit process because I have installed Office 2010 x32.
The OLEDB drivers for 32-bit and 64-bit applications are different.
If you only have the 32-bit driver installed, then 64-bit applications that attempt to use it will get this error. Similarly, if you have only the 64-bit version installed, then 32-bit applications that attempt to use it will get this error.
You say:
I try this code in other projects on my local machine and everything is working
Ergo, at least one of the two must be correctly installed.
To understand what's happening you could examine Environment.Is64BitProcess in both the application that works, and the one that doesn't. That will tell you which version is missing.
Then download and install the 32-bit or 64-bit version that's missing from:
http://www.microsoft.com/en-us/download/details.aspx?id=13255
You need AccessDatabaseEngine.exe (32-bit) or AccessDatabaseEngine_64.exe (64-bit)
Note that you may need to specify the provider as 'Microsoft.ACE.OLEDB.14.0' for the Office 2010 version (12.0 was for Office 2007).
After some hours I found a solution:
What were the steps, first I try to run the project on x86 - Properties/Build/Platform Target. Exception was thrown that I can't rebuild, because a registry was false. I create the registry. How to do it:
In notepad file paste this code and save it like reg file. Make the file name something to remember why you have it in the future(Fusion.reg).
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
"EnableLog"=dword:00000001
After that I had a problem because not all of my assemblies was readable by the application pool. Solution about that was going to IIS/Application Pools/Application Pool 4.0/General/Enable 32- Bit Applications. After that restart the IIS, close the project and open it again and everything was working with 32bit version.
I have application running in 32 bit mode. it tries to connect oracle DB using Oracle Client. Oracle Client is running in 64 bit.
string connectionString = #"Data Source=" + oracleDBName + ";User id=" + oracleDBUserId +";Password=" + oracleDBPwd +";";
OracleConnection con = new OracleConnection(connectionString);
try
{
con.Open();
if (con != null)
{
con.Open();
}
return true;
}
catch (OracleException)
{
return false;
}
I am getting targetinvocationexception when i call
con.Open();
Reason, It is not able to load 64 bit dll since the application is running in 32 bit mode.
I cannot change the application mode. I also cannot install the 32 bit Oracle client. How to solve this problem
Thanks in Advance
Oracle driver for .NET "requires native" client from Oracle. (It's not Java, where thin client exists)
Try instant client, it doesn't require installation.
http://www.oracle.com/technetwork/topics/winsoft-085727.html
Also, you can try ODBC .NET driver, but configure ODBC DSN to use Oracle driver from Microsoft (most windows installation has microsoft's odbc driver for oracle out of the box).
Again:
1) for 32bit application you need 32bit version of ODBC
2) oracle instant client should be available in the search path
In Windows 64bit there are two versions of ODBC admin panels for 32bit and 64bit applications. To run 32b version execute C:\Windows\SysWOW64\odbcad32.exe.
I have an asp.net / C# web application running in a Windows environment.
The project builds fine and runs perfectly on my local machine's VB.net development server.
However, when I publish to the real application server I receive the following error message:
[OracleException (0x80004005): The provider is not compatible with the version of Oracle client]
[TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.]
There is a version of this application currently up and running just fine, I am testing on the live server in a different directory. I even tried snagging the Oracle.DataAccess .dll from the working application but still get the same error message.
First off: The Oracle client/provider is a mess. And that goes for both the MS one (depreciated anyway) as well as the Oracle one.
In order to connect to an Oracle DB via the ODP.NET provider three things need to be setup properly:
Oracle client needs to be setup properly ( has nothing to do with the .NET provider, this referring to the installed oracle client usually in c:\oracle)
The ODP.NET provider needs to be compatible with the installed Oracle client
The architecture of client and provider and your application need to match, you cannot use the 64bit client with an x86 provider/application and vise versa
Usually the best is to have the newest version of both. But if you want to get rid of this issue once and for all use a third party oracle .NET provider.
UPDATE
One of the better ones is from DataDirect (no affiliation):
http://www.datadirect.com/products/net/net-for-oracle/index.html
It's not just installation (no oracle client necessary), but it's also faster, fully managed, x64 and general support is a way better than what you get with the ODP.NET one. It will cost you though.
The DevArt one is pretty decent as well (and much much cheaper):
http://www.devart.com/dotconnect/oracle/
We decided for the DataDirect for extensibility reasons, this should not be relevant to you however.
Here you can find a good compilation of third parties that build .NET providers, not limited to oracle though:
http://msdn.microsoft.com/en-us/data/dd363565
I came across the same scenario before
Reading this may help you some how ODAC Oracle for .NET
about your problem in your server you have to install the whole ODAC Client from oracle
the latest version now is 4.xx
i have installed it and everything works like charm
hope this helps :)
Take Care
I was able to solve this by searching for Oracle.DataAccess.dll on the prod server.
So instead of trying to build/deploy the project with the Oracle.DataAccess.dll from my development environment, I copied the .dll down from the prod server oracle client directory and included that as a reference instead. I also set the .dll properties "Copy Local = true" and "Specific Version" = true. So it looks like there is a mismatch between the oracle client version on my dev server and the prod server.
Equals, with Oracle.DataAccess.dll Works!!!!
//using Oracle.DataAccess.Client
object pdf = null;
var queryString =#"SELECT PDF FROM DIGITAL WHERE ID_DIGITAL=1001" ; //example
var ctx = new Entities();
var entityConn = ctx.Connection as EntityConnection;
if (entityConn != null)
{
var dbConn = entityConn.StoreConnection as OracleConnection;
dbConn.Open();
var cmd = new OracleCommand(queryString, dbConn);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
pdf = reader[0];
}
}
dbConn.Close();
}
return pdf;
In addition to the other suggestions, just try running Visual Studio as administrator.
I spent a lot of time messing around with the GAC and various versions of the Oracle.DataAccess.dll, and in the end just running VS as administrator got it to run.