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.
Related
I'm trying to connect my db with my asp.net web form but when i insert this to try the connection i've this error
OleDbConnection con = new OleDbConnection("Provider=OraOLEDB.Oracle;USER ID=C##FABIO;DATA SOURCE=ORCL");
//aggiungi un elemento alla tabella ESAMI
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
OleDbCommand cmd = new OleDbCommand("Insert into ESAMI(CODICE_ESAME,NOME_ESAME,ANAGRAFICA_CODICE_FISCALE) VALUES('" + codice_esame_text.Text + "','" + nome_esame_text.Text + "','" + codice_fiscale_text.Text + "') WHERE ANAGRAFICA_CODICE_FISCALE = '" + codice_fiscale_text.Text + "'",con);
cmd.ExecuteNonQuery();
con.Close();
how can i add the oracle provider?
When installing odac from command line (ODAC183Xcopy_x64.zip -> install.bat) I noticed that the path was updated (echo %path%) to include the oracle bin folder, so I thought everything should be working, but still received the Provider OraOLEDB.Oracle not registered error message, then I noticed that if I open a new command prompt window, the path to the oracle bin folder was no longer included in the windows path, so I had to manually add the paths for the oracle and oracle bin folders to the windows path environment variable.
Literally, it means the OleDB Provider for Oracle in not registered, you can register it with
%windir%\System32\RegSvr32.exe "<path of OraOLEDB11.DLL 64-bit version>"
%windir%\SysWOW64\RegSvr32.exe "<path of OraOLEDB11.DLL 32-bit version>"
However, usually this is not the root cause of your problem. In most cases the OleDB Provider is not installed at all. The bare Oracle Instant client does not include the Oracle Provider for OLE DB, either you install is separately or you need to enable the component in the Oracle Universal Installer.
You can download the Oracle Provider for OLE DB from here:
32-bit Oracle Data Access Components (ODAC) Downloads
64-bit Oracle Data Access Components (ODAC) Downloads
Note, the architecture, i.e. 32-bit vs. 64-bit must match with your compiler settings, you cannot mix it. Often people mix the 32 and 64-bit versions, they are named and looking equally.
The version of Oracle Provider for OLE DB (e.g. 12.2) must match with the version of the Oracle Client. You can install only one version of the Oracle Provider for OLE DB (i.e. one each for 32-bit and 64-bit), it's a limitation of the Windows COM architecture. So, run your installation carefully.
I have a .net core program running on ubuntu, and I need to add a connection to the database running on the same machine.
I created a test program on my windows machine which connected to and interacted with the database and tables I want perfectly (via a putty tunnel), but used MySql.Data.MySqlClient, which it would seems is windows specific. I copied the connection.cs code up to the ubuntu server (changed the namespace, referenced it it the main program etc.). When i try to build, it can't find MySql.Data.MySqlClient (type or namespace error on mysql).
Is getting it working a matter of a) loading MySql.Data.MySqlClient into the ubuntu machine, b) using a different package (if so does anyone know what) or c) doing it a totally different way.
I have tried looking at tutorials/ other SO posts to see their code but none of them are about connecting to a normal db hosted on the same machine.
Shamelessly copypasta'd from https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-connection-string.html
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "server=127.0.0.1;uid=root;" +
"pwd=12345;database=test";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
You do need to install MySQLClient on your ubuntu machine if it's not there already. Just select it in your package manager.
Also, if this doesn't work, verify that mysql is actually listening on a TCP port. It's possible that you're attempting a TCP connection but its actually listening on a socket.
https://dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.html
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
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
We're using the Oracle.DataAccess.dll assembly version 2.102.2.20 (32 bit).
I deployed our Web API application to IIS and tried openning and closing a connection:
private static void CheckConnectionUsingOracleClient(string connection)
{
var logger = DiContainer.Resolve<ILogger>();
try
{
logger.LogInfo("Trying to connect to " + connection);
// check whether you can connect to the shop using Oracle.DataAccess
using (var cnn = new Oracle.DataAccess.Client.OracleConnection(connection))
{
cnn.Open();
cnn.Close();
}
logger.LogInfo("Succeeded to connect to " + connection);
}
catch (System.Exception ex)
{
logger.LogError("Failed to connect to " + connection, ex);
}
}
On my local machine it's fine, but on this server it throws an exception when trying to initalize the the OracleConnection:
The type initializer for 'Oracle.DataAccess.Client.OracleConnection'
threw an exception. ---> Oracle.DataAccess.Client.OracleException: The
provider is not compatible with the version of Oracle client
I've installed Oracle client 11.2 (32 bit) on the server and I can see that in the GAC (c:\windows\assembly) the Oracle.DataAccess assembly is installed in 32 bit Processor Architecture. It works fine on one of our servers but not this one.
In IIS also, I've set 'Enable 32 bit Application' on the Application Pool.
How can it be fixed? I've spent over 10 hours so far trying different things :(
I'd ideally like to be able to use Oracle.DataAccess.dll without the need to install an Oracle Client on the server.
you can install Oracle.ManagedDataAccess
using Package Manager Console nuget
Pm> Install-Package Oracle.ManagedDataAccess
ODP.NET, Managed Driver is a 100% native .NET code driver. No additional Oracle Client software is required to be installed to connect to Oracle Database.
Update Code
using Oracle.ManagedDataAccess.Client;
private static void CheckConnectionUsingOracleClient(string connection)
{
var logger = DiContainer.Resolve<ILogger>();
try
{
logger.LogInfo("Trying to connect to " + connection);
// check whether you can connect to the shop using Oracle.DataAccess
using (var cnn = new OracleConnection(connection))
{
cnn.Open();
cnn.Close();
}
logger.LogInfo("Succeeded to connect to " + connection);
}
catch (System.Exception ex)
{
logger.LogError("Failed to connect to " + connection, ex);
}
}
Oracle.DataProvider version 2.102.2.20 decrypted
2: .Net version (can be 1 for .Net 1 - 1.1, 2 for 2 - 3.5 and 4 for 4
- 4.5)
102: Oracle version: Oracle 10.2
2.20: Oracle Data access version
You should check
.Net version (should not be higher than your .Net compiler)
Oracle client version (should not exceed Oracle Client version)
Both Oracle client and Oracle.DataProvider are 64-bit or Oracle.DataProvider is 32 bit and Oracle client is either 32 bit or supports legacy 32 bit mode
After installation make sure:
PATH is updated with Oracle dlls location: \product\12.1.0\client_1\bin and \product\12.1.0\client_1
Restart the server.
Enable 32bit for the App Pool in IIS.