(Lviv community of .NET developers)

OracleDecimal and ODP.NET IConvertable exception

September 30, 2008 10:49 by alexk

Oracle ODP.NET

I'm working now on a new project that in internals use ODP.NET - ORACLE Data Provider for .NET and latest Oracle 11g.

First of all I want to mention that ODP.NET is a great disappointment for me. In writing of very simple a stupid code ODP give me so many issues that I start to think that ORACLE completely loose own mind and release very unstable library for developers. I loose 2 days for fighting with found issues and I hope my article will help others a lot.

Simple Scenario that does not work in ODP.NET

Let's start from the simple scenario: Create typed DataSet with several tables, infill dataset by the data and update database by that data. Primary keys of the rows must be updated by Adapter automatically on Update method call.



Step #1:

I start implementation from defining tables on ORACLE side by SQLDeveloper tool. That part was easy enough with exception of auto incremented primary keys implementation. But here me helps a lot a great article: http://jen.fluxcapacitor.net/geek/autoincr.html
Tips: SQL Developer already has a defined template for that operation, but I found that at the design of the last table. Bad for me.

Step #2:

Define Typed Dataset. That was really easy. I configure Oracle Connection in visual studio and just drag&drop tables into dataset. Then I decide to check and that was i really good move. I found that Dataset well catch primary keys and relations, but auto increment fields not catched well.
So I make small modification to all primary keys columns. I set properties:
AutoIncrement - "True"
AutoIncrementSeed - "-1"
AutoIncrementStep - "-1"

Step #3:

Define INSERT commands that returns us Primary key value from DB side. It was not easy task, but another article helps me a lot: http://foxsys.blogspot.com/2007/06/oracle-newly-inserted-row-using.html

After reading that article INSERT creation become very easy.

But at that point I found several interesting issues:

issue #1:

on INSERT command execute oracle throw me exception ORA-01722.

4 hours of fiting with that issue give me a solution: http://tgaw.wordpress.com/2006/03/03/ora-01722-with-odp-and-command-parameters/
Property of the OracleCommand.BindByName must be set to "True" value, otherwise oracle implementation uses internal indexes for sending/getting parameters in order that it think is right.

issue #2:

By default OracleCommandBuilder that creates Commands set property UpdateRowSource to "None" value. Such behavior force me to spent 4 hours for finiding that solution.

My question: what for Microsoft design concept of parametrized queries if it not used by others?! Why default parameters of the classes in ORACLE implementation are so different in compare to Microsoft implementation?

Real shame to the ORACLE developers that don't know how to set correctly default parameters.

Step #4:

Create DataAdapter and update DB by infilled data. What can be easier you ask? This is the point where you are wrong.

issue #3

First run of the code and you got nice exception:

System.ArgumentException occurred
  Message="Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal' to type 'System.IConvertible'.Couldn't store <28> in ID Column.  Expected type is Decimal."


make a little search on Google and you will see on ORACLE forum that this issues not resolved more then 2 years!!! wow!
http://forums.oracle.com/forums/thread.jspa?threadID=613812&tstart=0&messageID=2467419

Are you still searching for solution? Ok, I'll help - I found the solution. Just add handler to the event DataTable.ColumnChanging and in event handler convert Oracle data types to the standard, well convertible types.

VB.NET:
      AddHandler table.ColumnChanging, AddressOf OracleConvert_ColumnChanging

   Private Sub OracleConvert_ColumnChanging(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs)
      If TypeOf e.ProposedValue Is OracleDecimal Then
         e.ProposedValue = CType(e.ProposedValue, OracleDecimal).Value
      End If
   End Sub

After that fix my journey of ODP.NET simple usage scenario is over. or not?

At the end of the day

I hope that simple article helps you a little with ODP.NET and ADO.NET.

I still have one more issue: DataAdapter.Update command does not update relations for other rows. This is a new quest for me...

BTW if you will try to do the same thing by using System.Data.Oracle provided by Microsoft everything will work fine from the first run.


Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

September 30. 2008 13:01

Issue mentioned in last paragraph fixed by proper relations customization in DataSet. Don't forget to set CASCADE updates.

alexk

March 18. 2009 07:47

Thanks buddy. It helped me a lot.

Ravi

April 24. 2009 21:51

Thanks for brain-dumping your troublesome experience. ODP.Net sucks, Oracle Sucks.

Henry

June 26. 2009 01:31

interesting stuff. thanks!

?????????

August 4. 2009 22:09

Great post! Keep up the good work!

Voguishchic

August 8. 2009 07:03

Times change. Recently I was interacting with a team that was using ODP.NET. And they had this stored procedure written in SQL server which they were moving to Oracle DB. They had some challenges in porting their data access code to support Oracle. One of them was – ODP.NET requires all parameters (even if they have default values) to be passed to the Stored Procedure and also expects them in the same order. But with SqlClient the same is not required. Solution to this is use BindByName property of OracleCommand class. Let me elaborate through a small sample code for better understanding:

smet clothing

December 4. 2009 01:17

Thanks, your code really helped me. I figured out, that you can also resolve this problem by setting the DbType-Property to the expected type before adding the parameter to the Parameters-Collection.

LBR8

January 30. 2010 09:48

i found your blog, nice post, good theme, very helpfull, keep post, thanks

Properties in Infonavit

February 17. 2010 07:08

This is really nice and interesting blog.I m glad to know.

Vino Bio

February 28. 2010 02:16

좋은 게시물 주셔서 감사합니다

Oven Parts

March 1. 2010 15:02

It helped me a lot.

GHD MK4 IV Pure

March 3. 2010 11:22

Great looking site! Maybe you should use ads from Prosperent network. They pay based on sales not a clicks!!! That means way better money than adsense or any PPC:) If you are interested send me an email. I will send you invitation code. Cheers.

Amik

May 14. 2010 10:42

I finally realized that this blog is worth reading

rome tours

July 1. 2010 18:46

Thanks for the help.

waterproofing | roofing

July 4. 2010 07:19

As all people understands respect is one of the most essential amongst people's existence. Only respect one another to acquire along nicely and I believe that leaving one's opinion may be a behavior of respect. Do you feel so?

supra vaider high

July 5. 2010 08:14

Thanks for writing this nice article, I will visit your blog again, it actually catches my attention!

Air force one

July 6. 2010 02:13

Great Article!

James | Broke

July 6. 2010 23:40

Couldn't agree more.

Peeing

July 7. 2010 10:26

This is easier and surely gives comfort to us. I'll definitely bookmark your website for additional reading!

Air force one

July 7. 2010 10:43

Another excellent article like always a good way to spend time taking a look at

PeeQ

July 9. 2010 12:30

you know what? I love reading your blog. It opened up my minds about things. Things that I did not realize at the first place. There are a lot to learn. Thanks for the good article by the way.

shoppingcool

July 10. 2010 07:43

Trubloods.com is really the site specializing in providing just about all of the many advantages and darkness from the hit show True Blood. True Blood will be named since the synthetic blood how the japoneses have got created now pumpkin heads come out from the night to try and also exist together with humans. You follow Sookie Stackhouse because the actual lady bargains with the actual chaos that exists on earth. There is certainly romance, humor, action, and several a great deal extra as an individual observe pumpkin heads, human beings because well as supernaturals conflict in the community regarding Bon Temperatures, Louisiana. View totally free avenues at trubloods.com!

supernatural

July 10. 2010 11:39

The secret to productive goal setting is in establishing clearly defined goals, writing them down and then focusing on them several times a day with words, pictures and emotions as if we've already achieved them. http://www.clicknpayday.com

pay day loans

July 12. 2010 01:55

Nice one buddy it Help me lot:P

Payda Loan

July 12. 2010 21:43

Thank you very much for this idea.

Motorbike Jeckets

July 13. 2010 01:57

i appreciates your work dude. Really..step by step services ..i like that

bad credit personal loans

July 13. 2010 19:15

Wow i did not realize at the first place. There are a lot to learn.Thank you very much for this sharing.

Business Process Outsourcing

July 14. 2010 17:11

Great post! Keep up the good work!

vibram fivefingers

July 14. 2010 18:51

Greetings from California

color name badges

July 14. 2010 19:40

Thios really very nice article.

Offshore Outsourcing

July 14. 2010 20:12

Thanks for providing us this article.

BPO Services

July 14. 2010 21:48

Yeah this the excellent article.

Motorbike clothing

July 15. 2010 00:37

Thank you very much for this nice idea.

Caberg helmet

July 15. 2010 06:19

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

shopcool

July 15. 2010 12:01

Hey, check out this website had been you may Xbox 360 games, accessories and points for completely zero cost! All you have to do is sign up and full some surveys and you are set. It's 100% secure and free! www.FreeGamesFor360.com

rebel

July 16. 2010 09:00

Wow, always excellent to find out other persons through the hole world in my searching, I definitely appreciate the time it should have taken to set together this cool article. friendly regards

Shad Whitheld

July 16. 2010 09:56

Hey, check out this internet site have been it's possible to Xbox 360 games, components and points for totally zero cost! All you have to perform is sign up and full some surveys and you are set. It is 100% secure and free! www.FreeGamesFor360.com

rebel

July 16. 2010 21:01

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.

Air force one

July 16. 2010 22:40

Aw, this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.

dentist

July 17. 2010 08:31

Took me time to examine all the comments, but I seriously enjoyed the post. It proved to be really useful to me and I'm sure to all the commenters here! It is always great whenever you can not only be informed, but in addition entertained! I am sure you had enjoyable writing this post.

pissing fetish

July 17. 2010 08:31

Well written article, well researched and useful for me in the future.I am so happy you took the time and effort to make this. Best of luck

peeing fetish

July 19. 2010 05:29

There are a lot to learn.Thank you for this informative post.

Cheap Motorcycle Leather Jacket

July 19. 2010 07:28

This is really good story.More people need to read this and understand this side of the story.Thank you for this sharing

Motorcycle jeckets

July 19. 2010 10:00

This is new ideas and also helpful for others. I really appreciate work done on this blog.Thanks for this informative post.

viper Helmet

July 20. 2010 11:45

hosting rating

hosting rating

July 20. 2010 11:45

host guide

host guide

July 21. 2010 13:50

Following exploring a legitimate hotmail password hack computer software, I uncovered this software. Be cautious with it even though, I am not guaranteed if it really is legal to utilize it to hack someones hotmail or yahoo account password, its only legal to apply it all on your own personal when you forget the password. http://www.hotmailpasswordhack.net

hotmail crack

July 24. 2010 09:46

ODP.NET makes using Oracle from .NET more flexible, faster, and more stable. ODP.NET includes many features not available from other .NET drivers, including a native XML data type, self-tuning, RAC optimizations, and Advaned Queuing API.

payday loans online

July 24. 2010 17:01

with the real estate market hopefully picking up perhaps I will hire a new assistant and have time to maintain with my blog

gary

July 25. 2010 03:31

I hope to be back here soon

Grande Dunes

July 25. 2010 05:59

I am in the Myrtle Beach marketplace and still have definatly been effected because of the market

Myrtle Beach Short Sales

July 27. 2010 17:07

Thanks, your code really helped me. I figured out, that you can also resolve this problem by setting the DbType-Property to the expected type before adding the parameter to the Parameters-Collection....

Home for Sale

Add comment


(Will show your Gravatar icon)