📜 ⬆️ ⬇️

Transition from ODAC 10 to ODAC 12

Good morning everyone!

It took us here quickly to switch to Oracle.DataAcess 12th version in our .Net project. And everything went fine until we tried to start the application. In a couple of thousand places a type error suddenly fell out:

Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal' to type 'System.IConvertible'. 


Searching the forums gave the answer - in the 11th version something concrete was replayed in the OracleParameter and, as a result, all Convert.ToXXX in our project fell off.
As a solution, the Mark Williams blog oradim.blogspot.ru/2009/08/odpnet-vb-and-from-type-to-type-is-not.html proposes the following:
')
OracleDbType vs. Oracle provider type is returned. Also, the current ODP.NET Beta (11.1.7.10) exposes a new property for the OracleParameter class: OracleDbTypeEx This property allows you to use it.


Automaton this property is not initialized. In the internals of ODAC through dotPeek, the following piece was discovered:

  public OracleDbType OracleDbType { get { return this.m_oraDbType; } set { if (this.m_oraDbType != value) { OracleDbType oracleDbType = value; if (oracleDbType < OracleDbType.BFile || oracleDbType > OracleDbType.Boolean) throw new ArgumentOutOfRangeException(); this.m_oraDbType = oracleDbType; } this.m_bSetDbType = false; this.m_enumType = PrmEnumType.ORADBTYPE; this.m_bOracleDbTypeExSet = false; } } public OracleDbType OracleDbTypeEx { get { return this.m_oraDbType; } set { this.OracleDbType = value; this.m_bOracleDbTypeExSet = true; } } 


Those. the necessary property from the parameter constructor is not initialized itself; you need to explicitly add its setting to the code so that the field this.m_bOracleDbTypeExSet becomes true.
We absolutely did not want to peel a huge number of command declarations, since we already had our own library with extender methods for OracleCommand and we added another method:

 public static int ExecuteNonQueryExt(this OracleCommand cmd) { foreach (OracleParameter param in cmd.Parameters) { param.OracleDbTypeEx = param.OracleDbType; } return cmd.ExecuteNonQuery(); } 


And then autocorrect for the ExecuteNonQuery project on ExecuteNonQueryExt and bingo! Everything started and flew. :-)
Perhaps there is some more painless way to accomplish this transition without rewriting half of the project, but the solution was not found on the forums. Although the rake is quite old and many have stepped on them even at the time of the 11th version.

Source: https://habr.com/ru/post/240427/


All Articles