So I am having trouble connecting to an Oracle XE 11g database in visual studio. The Ultimate aim here is to make a webpage I can run on my local machine and send sql to on my local net. From looking around it seems other people have had this problem, but I cannot grasp how they managed to solve it, and it appears I am running all the right software, so I shouldn't be getting this error. This error is this BadImageFormatException, and it suggests that there is a 32 bit/64 bit mismatch somewhere, but my oracle edition seems to be the right one as you can see from the following command.

SQL> SELECT * FROM v$version;

BANNER
--------------------------------------------------------------------------------

Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

SQL>

The full text of this Visual Studio dialog is as follows;

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. 

I am basically trying to add a connection using that data connections node in my ASP.NET project.

I even tried to convert my project to x64 through the solution properties page, but it keeps changing the platform to Active(x64), so I am not sure what is going on. I even tried changing it to x86, knowing that would probably be wrong, but I figured I might as well try everything. Does anybody else have any ideas about how to fix this. I also tried to install a 32 bit client along side the other one, but the oracle instillation does not like that. My compiler should be able to handle x64 and x86 right? Is there an easy fix to this?

Am running Visual Studio 2010.

Don't know if this is any help but this works for me.

Connection string is:

<add name="OracleConnection" connectionString="User Id=MyUserId; password=MyPassword; Data Source=MyServer:1521/orcl.MyUrl.co.uk; Pooling=false;"/>

And code is:

        private static IEnumerable<Document> GetDocuments(string selectText)
        {
            var documents = new List<Document>();

            using (var oracleConnection = new Oracle.ManagedDataAccess.Client.OracleConnection(ApplicationConfiguration.ConnectionString))
            {
                using (var oracleCommand = new Oracle.ManagedDataAccess.Client.OracleCommand(selectText))
                {
                    oracleCommand.CommandType = CommandType.Text;

                    oracleCommand.Connection = oracleConnection;

                    oracleConnection.Open();

                    using (var reader = oracleCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var doc = new Document
                                {
                                    DocId = reader.GetInt32(0),
                                    DocumentType = (DocumentType) Enum.Parse(typeof (DocumentType), reader.GetString(1)),
                                    DateStored = reader.GetDateTime(2),
                                    ImageBlob = (MemoryStream) reader.GetStream(3)
                                };

                            documents.Add(doc);
                        }
                    }
                }
            }

            return documents;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.