How do I use Oracle from .NET?

前端 未结 5 936
星月不相逢
星月不相逢 2021-01-30 11:45

Unfortunately, I\'m trying to use Oracle from .NET and it\'s like going to back to 1997. Explaining things properly is a sign of weakness and the registry and environment variab

5条回答
  •  别那么骄傲
    2021-01-30 12:05

    I don't believe this is a path issue. "An attempt was made to load a program with an incorrect format." is an error that almost always means that you are mixing 32-bit and 64-bit assemblies and DLLs in .NET.

    I noticed you installed the 64-bit Oracle client, I am assuming since the DSN creation worked that you are on a 64-bit version of the OS? Your problem could be from a number of related scenarios:

    • Your copy of OraOps11w.dll could be a 32-bit assembly and you are using it in a 64-bit app
    • Your copy of OraOps11w.dll could be a 64-bit assembly and you are trying to use it from a 32-bit app
    • one of the unmanaged dependencies of the Oracle Data Provider for .NET is 32-bit and is failing to load into your 32-bit app (or vice versa)

    I believe if your app targets x86 specifically, you must install the 32-bit Oracle client package regardless of the underlying OS platform (e.g. you still would need the 32-bit Oracle client for a 32-bit app even if you were using a 64-bit version of Windows)

    a couple of things to check:

    • Check your "Platform Target" setting in your assembly that calls the Oracle provider: x64 will always try to run as 64-bit, x86 will always try to run as 32-bit and "Any Platform" will JIT compile to the target OS architecture at runtime (32-bit on an x86 system and 64-bit on a x64 system)
    • Run OraOps11w.dll through corflags.exe (see details at this SO post) to see if it is 32-bit, 64-bit or "Any CPU"

    Lastly, have you tried to built-in .NET data provider for Oracle (System.Data.OracleClient namespace?)

    That's the best I can do since I don't know more about your projects settings for your app.

提交回复
热议问题