Oracle 10g and .NET: it just works

OK, this is sure to be really silly stuff for some of you, but as I do 9x% of my work with SQL Server, taming the Oracle beast is a real challenge for me. The very first round, filling a dataset:

using Oracle.DataAccess.Client;
...
 
    using (OracleConnection con = new OracleConnection("User Id=xyz;Password=zzzz;Data Source=orcl"))
    {
        try
        {
            OracleDataAdapter da = new OracleDataAdapter("select * from HR.EMPLOYEES", con);
            da.Fill(this.EmployeesDS.EMPLOYEES);
        }


        catch (OracleException ex)
        {
            EventLog.WriteEntry(ex.Message, EventLogEntryType.Error)
        }
    }

Here, ORCL is the Oracle instance (TNS) that I want to connect to and HR is the schema that I want to use. For this code to compile, we must make a reference to the Oracle.DataAccess assembly which lives (in the standar Oracle installation) in C:\oracle\product\10.1.0\Db_2\BIN. By the way, you need this folder in your PATH (yes, your PATH, that old Windows artifact) and read access to the folder (this is relevant to me, as I've been developing as a non-administrator since a few weeks ago, so far so good, I haven't become more productive but I feel better). This code also works as is if you use the Visual Studio 2003 Oracle Data Provider, all you have to do is change the using line and referencing the System.Data.OracleClient assembly. By the way, anybody out there has any suggestions as which data provider is better?

17 Comments

  • 10g's ODP.NET is indeed nice. We'll release Oracle 10g support with ODP.NET later today for LLBLGen Pro :)



    There is one caveat with 10g's ODP.NET: ExecuteNonQuery doesn't return the amount of rows affected when the query is a batched query (for example an INSERT + a sequence CURRVAL select for reading back the used sequence val).



    About which provider is better: we had long doubts which to pick: MS' provider or Oracle's. ODP.NET is a big download and has client restrictions, while the MS provider apparently seems to work fine with 10g and every client that can connect to 8i or higher. We went for Oracle's because of its solid REF CURSOR support: you can simply bind these to a dataset and the adapter fills the dataset nicely. I know for a fact that a lot of procs on Oracle use REF CURSOR to return sets so this is really a plus.



    Also a plus is the bugfixes Oracle does to its provider while MS doesn't fix bugs in the Oracle provider because that would require a bugfix to .NET and these apparently aren't released.



    I do wonder though if .NET 1.1's provider will work with 10g easily. After all, what I said about the ExecuteNonQuery return value can break a lot of code in .NET because suddenly no rows are affected, which will lead to concurrency exceptions in the data-adapter.



    I also doubt you can simply change a using line and that's it. ODP.NET has some aspects like the type of returned values, which can make code become non-portable between the two providers.

  • Wow, I mean, this is great feedback. The REF CURSOR part and the bugfixes comment are useful. About changing just one line to switch providers, all I said is that it works in my very simple example, I had no hopes about it in real life situations (hence the urge to know which data provider is better). By the way, do you have anything to comment about performance?


  • Your style is really unique compared to other folks I have read stuff from. Thanks for posting when you've got the opportunity, Guess I will just book mark this web site.


  • Hello, I do think your site may be having web browser compatibility problems. Whenever I look at your site in Safari, it looks fine however, when opening in I.E., it's got some overlapping issues. I simply wanted to give you a quick heads up! Aside from that, fantastic website!


  • Having read this I thought it was really informative. I appreciate you taking the time and energy to put this content together. I once again find myself spending way too much time both reading and posting comments. But so what, it was still worthwhile!


  • The very next time I read a blog, Hopefully it won't disappoint me as much as this particular one. After all, Yes, it was my choice to read through, nonetheless I actually believed you would have something interesting to say. All I hear is a bunch of moaning about something you can fix if you were not too busy searching for attention.


  • This is a topic which is close to my heart... Many thanks! Where are your contact details though?


  • Good article. I am experiencing a few of these issues as well..


  • Hi there! I could have sworn I’ve visited this website before but after going through some of the articles I realized it’s new to me. Anyhow, I’m certainly happy I discovered it and I’ll be book-marking it and checking back regularly!


  • I’m impressed, I must say. Seldom do I come across a blog that’s both equally educative and amusing, and let me tell you, you have hit the nail on the head. The issue is something not enough folks are speaking intelligently about. I am very happy I came across this in my search for something regarding this.


  • Way cool! Some extremely valid points! I appreciate you penning this write-up plus the rest of the site is also very good.


  • Hello there, There's no doubt that your web site could possibly be having web browser compatibility problems. Whenever I look at your web site in Safari, it looks fine but when opening in Internet Explorer, it's got some overlapping issues. I merely wanted to provide you with a quick heads up! Aside from that, wonderful blog!


  • I really like it when folks come together and share ideas. Great website, stick with it!


  • Hello there! This article could not be written any better! Going through this article reminds me of my previous roommate! He constantly kept preaching about this. I am going to send this information to him. Pretty sure he'll have a very good read. Many thanks for sharing!


  • I blog quite often and I really appreciate your content. Your article has truly peaked my interest. I'm going to take a note of your site and keep checking for new information about once a week. I subscribed to your RSS feed as well.


  • Saved as a favorite, I love your site!


  • You need to be a part of a contest for one of the greatest sites online. I most certainly will recommend this site!

Comments have been disabled for this content.