Pages

Monday, December 13, 2010

oracle.dataaccess conversion from type oracledecimal to type integer is not valid

Imports System
Imports System.Data
Imports Oracle.DataAccess.Client
 
Module Module1
  Sub Main()
    Dim con As New OracleConnection("user id=scott;password=tiger;data source=orademo")
    con.Open()
 
    Dim cmd As OracleCommand = New OracleCommand("getoutnum", con)
    cmd.CommandType = CommandType.StoredProcedure
 
    Dim p1 As New OracleParameter
    'this will not work as expected with .NET 2.x and higher and ODP.NET
    'p1.OracleDbType = OracleDbType.Int32
 
    'use DbType and not OracleDbType to get the parameter as a .NET data type
    p1.DbType = DbType.Int32
    p1.Direction = ParameterDirection.Output
 
    cmd.Parameters.Add(p1)
 
    cmd.ExecuteNonQuery()
 
    Try
      Dim a As Integer = p1.Value
      Console.WriteLine("val is {0}", a)
    Catch ex As Exception
      Console.WriteLine(ex.Message)
    End Try
 
  End Sub
End Module

web.config driver dll change for the x64 or x86

Issue: An attempt was made to load a program with an incorrect format 64 bit

Add the following binding policy:

Code Snippet
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" />
        <bindingRedirect oldVersion="2.0.0.0-10.9.9.9" newVersion="2.102.3.2" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
If you want your application to force using 64-bit client when running in 64-bit more (tested on AMD 64) use the following code in app.config of your file:
 
Code Snippet

    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342" processorArchitecture="amd64" />
        <bindingRedirect oldVersion="2.0.0.0-10.9.9.9" newVersion="2.102.3.2" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
   
processorArchitecture and bindingRedirect can work wonders for you... changing the redirections and processorArchitecture will help u eliminate the badImageException.