Coding Power Unleashed

Programming blogs containing .NET, C#, LINQ and Delphi experiences

Wednesday, January 20, 2010

Connecting (struggling) to Oracle database

This week I have been working (read struggling) on connecting a C# .NET application to Oracle. In the end I was trapped between 32 bits vs 64 bits, .NET Oracle providers and 32 bit OLE DB providers.

First of all I challenged this task, not bothered by any knowledge about Oracle. I did know that if you want to connect to an Oracle database you have to install the Oracle Client on the client machine. This only 1,7 Gb (!) download (Oracle 11g) happily told me that my Windows 7 version (real version 6.1, 64 bits) was not certified for the job. Only Windows 6.0 was.

Huh, now what?

After some googling found this blogpost about how to trick the setup to install on Window 7 (6.1) anyway.
After that it installed gracefully (some warnings…), time to startup VS to give it a spin!

Well not. That app that I am writing connects besides Oracle and SQL Server to an Access database. Because the Jet OLEDB driver for Access is 32 bits only I am doomed to target the x86 platform for now. No problem, however the 64 bits Oracle client can not connect targeting the x86 platform. Getting a BadImageFormatException:

[InvalidOperationException: Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed.]

(Still having the feeling it is the other way around, because I have the 64 bit Oracle client components installed)

Huh, now what?

Because the ADO.NET provider for Oracle from Microsoft suits well in the other technologies I tried to google more information. As it seems this driver is by the coming of .NET 4.0 deprecated. So on second thoughts not a good choice after all. Using the .NET provider from Oracle (ODP) then? Can I install 32 bits Oracle client on 64 bits machine? Who knows.

Fortunately Twitter came to rescue someone pointed out that there are third party solutions, which can connect to an Oracle database even without the Oracle Client.

So I tried Devarts dotConnect, which indeed can connect without the Oracle Client, isn’t that just great! Within 5 minutes I was connected (either 32 or 64 bits).

So if you want to connect to Oracle on .NET, keep some sparetime afterwards, I would suggest using third party components for it!

Friday, November 06, 2009

Casting lists using LINQ #2

In my previous post I showed the LINQ way to cast List<SomeDeriveType> to List<SomeBaseObject>.

IEnumerable<BaseObject> baseObjects
= DerivedList.Cast<BaseObject>;
Great stuff!

As @jamiei commented this will raise an exception if the cast fails. OfType<T> will return only the elements of type T despite the fact that you have different derived types in one list. So suppose you have an Animal class and a Cat and Dog class that derive from Animal you could do something like this:
List<Animal> animalList = new List<Animal>();
animalList.Add(
new Dog("Dog1"));
animalList.Add(
new Dog("Dog2"));
animalList.Add(
new Dog("Dog3"));
animalList.Add(
new Cat("Cat1"));
animalList.Add(
new Cat("Cat2"));
animalList.Add(
new Cat("Cat3"));
//Get the dogs
IEnumerable<Dog> dogList = animalList.OfType<Dog>();
//Get the cats
IEnumerable<Cat> catList = animalList.OfType<Cat>();

LINQ makes it very easy to seperate the Dogs from the Cats!

Labels: ,

Wednesday, November 04, 2009

Casting lists using LINQ #1

I have been doing lately much work on a .NET 3.5 application using LINQ. LINQ is a great way to manipulate data. I still consider myself a 'LINQ rookie' so I discover everyday something new.

One thing that floated around my head a while was the problem that you can't cast a List<SomeDerivedObject> to List<SomeBaseObject>.
A poorman's solution to this was to loop the objects from the one list into the other list. Not an elegant solution though.....

I discovered that you can do this easily with LINQ. When you use a IEnumerable<T> you can do this like this:

IEnumerable<BaseObject> baseObjects
= DerivedList.Cast<BaseObject>;

Where DerivedList holds objects that inherit from BaseObject.
With a List<T> you could do something like this(copy):
List<BaseObject> baseObjects =
new List<BaseObject>(DerivedList.Cast<BaseObject>());

A great LINQ resource is 101 LINQ samples on MSDN.

Labels: ,

Wednesday, August 05, 2009

Go see Delphi 2010

The first Delphi 2010 sneak peek video's showed up on the Internet. The first sneak peek shows some new IDE features like IDE insight, an everywhere context sensitive IDE navigation system.

Anders Ohlsson has a nice sum up of all the related Delphi 2010 blogposts.

Tuesday, June 30, 2009

CodeRush for free, not for Delphi Prism

As blogged before you know that I think DevExpress CodeRush totally rocks!
Did you know that you can get a lot of this functionality for free?

Mark Miller has got a very nice list of features that are available in CodeRush Xpress for C# and Visual Basic inside Visual Studio 2008. All for free!
In the full product you will get even more, check out the differences in this article: Moving up from CodeRus Xpress to CodeRush

Delphi Prism
The downside of all this good stuff is that Delphi Prism is not supported. The fact that the original CodeRush was a pure Delphi IDE product, I can not believe that it will not be supported in the future.

Labels: , ,

Monday, June 29, 2009

The future of Delphi

I haven't had much time lately to follow everything on the Delphi side of the fence, but there is a lot going on.
Stefaan Lesage has a nice write up on this future, The future of Delphi looks brighter than ever before.

A very nice read, sums up everything that is cooking in the labs, including the roadmap.

Monday, May 18, 2009

Applying Domain-Driven Design - Book review

Before this weekend I got my copy of Applying Domain-Driven Design and Patterns by Jimmy Nilsson.
adddp
Althought the title, in my opinion should be "Applying Domain-Driven Design, Test Driven Design and Patterns", because beside DDD it covers a great deal of TDD also.
Design patterns for me were always a bit fuzzy, something from far-far-away land. However lately I am having more and more interest in Test Driven Devleopment and that software design method drives you towards better, testable, design, and Domain Driven Design seems to being just doing that.

Back to book
When you order a book about Design Patterns you expect it to be more a reference then a complete read, because the stuff looks to be boring ('dry stuff' as we say here), without trying it out.
In this book however the author takes you on a journey of software architecture, design and decisions. The book gives lots of "Aha!", "Huh?" and "Done that" moments which, I guess, keeps you awake.
It is loaded with lots of solutions for particular (recognizable) software problems, not just pushing Design Patterns, but making you think more about the right solutions, which always depends....

In just three days I have read half of the book already! For me that is rare.

So if you are interested in better software design I can highly recommend this book, it reads like a breeze!