Month: April 2010

Create System DSN with oracle

Let’s say we want to connect our oracle database server to this new local console application we are going to build, we will first need to create a System DSN with oracle via Window’s ODBC.

We will do a tnsping command in a cmd box – c:\>tnsping network.domain (for example Melliepc.mellie) to see if our connection does exist.

Used TNSNAMES adapter to resolve the alias
(HOST = Melliepc)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = Myoradb))) OK (220 msec)

Next step is to install the Oracle Instance Client Basic on our machine and don’t forget to install the Oracle ODBC
C:\Program Files\Oracle\instantclient_10_2\odbc_install.exe] as administrator (this is to Register Oracle ODBC).
That was not so hard, now we are gonna create a new system-DSN:
go to your Configuration screen –> administrative tools (ODBC) as administrator.

Choose System-DSN –>Add new, select the correct source, in my case this will be Oracle instantclient_10_2.


All that is left now is to fill in the correct values for our database and click the test button, if successful, the connection to our database is ready. Yay!


Now we can start using data from the oracle database in our project, What a joy!

Tooltip of the month Part 1

As of today i will point out helpful or smart tool tips available on the on the web every month.

Today’s tool tip is all about the start-up of a Sql server migration project and is more an assist tool than a really geeky code tip, but it can be very handy when you have to plan your server migration, especially if you are working in a large or client environment.

Microsoft Assessment and Planning Toolkit (MAP)
Microsoft brings you a simple quick assessment tool, a tool to assist migration planning for example..

MAP toolkit provides you with a very easy tool to find out where your servers are and provides you with an automated excel generated overview in just a few clicks from your machine:

Quick tip for SQL server overview: Select a database ‘create a new one’ and gather server information. ‘identify servers capable of running 2008’ click ’asses server hardware’ click ‘use active directory domain services’ or ‘import computernames from file’ if you already know where your servers are and just import the flat file. wmi: login for the local service as administrative
it takes about 30 minutes and you get an output of al the servers, their status and a possible migration advice.

Wow, it’s really that simple, now i can take this list to the executive and convince him/her of my consolidation plan.

The Beta review program is now open, you can register here:

Back to Basics: Linq and Lambda

Here’s an extra back to basics post. After updating the previous posts with the generics stuff and all those cup of T’s, it’s time for something easy, clean and dirty.
Well, it probably won’t be dirty.

Maybe you’ve noticed how I completely bypass SQL, be it MySQL, MS SQL or whatever. That’s because I don’t like to repeat myself in my code. I like to keep things DRY. That’s why I love Linq. With Linq you can query objects just like how you would query records in a table. With Lambda expressions, you can beautify your code even more.

Bottomline is: at Itslet we want to keep our code simple, elegant and beautiful.
What can I say: we are women. Haha.

Fire up VS and create a Console App!

Let’s create a simple array for an.. animalfarm.

string[] myFarm = {"varken", "koei", "kip", "geit"}

Now the same with the var keyword:

var myFarm = new[] {"varken", "koei", "kip", "geit"}

If you hover over the elements in the array, you notice that they get typed as a string anyhow.

Hover over

A var is not the same as a variant in Visual Basic. In VB we could say: Dim Animal As Variant and then initialize it with Animal = “koei”.
With a var, we need to initialize immediately:

var animal = "koei";

And it will know it’s a string implicitly.

Now let’s query the AnimalFarm with Linq. With Linq we can use queries on almost every collection.

var myFarm = new[] {"varken", "koei", "kip", "geit"}

var beesten = from b in myFarm
                    select b;

foreach (var beest in beesten) {
Console.WriteLine("Er staat een {0} in wei.", beest);

This is the output:


Here’s another example of a Linq query:

var myFarm = new[] {"varken", "koei", "kip", "geit"}

var beesten = from b in myFarm
                    where b.Contains("i")
                    select b;

foreach (var beest in beesten) {
Console.WriteLine("Er staat een {0} in wei.", beest);

Now if I run the program it will only show the animals with an “i” in its name.

You can perform a whole plethora of Linq methods on the AnimalFarm collection:


It’s hard to believe but we can beautify this even further. With Lambda’s. Lambda expressions are the follow-up to delegates from C# 2.0. A Lambda e.g. follows after one of those Linq methods (Contains, Select, Take, Where, Single etc.).

static void Main(string[] args)
//string[] myFarm = { "varken", "koei", "kip", "geit" };
   var myFarm = new[] { "varken", "koei", "kip", "geit" };

//var beesten = from b in myFarm where b.Contains("i") select b;
   var beesten = myFarm.Where(b => b.Contains("i"));

  foreach (var beest in beesten) {
    Console.WriteLine("Er staat een {0} in wei.", beest);

See how the Lamda expression is an argument for the Where function? Isn’t that BEAUTIFUL?
Also notice how short and elegant the code is?

Well, I think this is enough awesomeness for today.

You can download the files of this trivial AnimalFarm app here: AnimalFarm