October 24, 2008

Connecting to Oracle is slow on ADO.NET under Vista

Filed under: .Net — Jeff @ October 24, 2008 12:13 pm

Our application uses the “System.Data.OracleClient” library to connect to our Oracle database.  Something like this:

OracleConnection connection = new OracleConnection(     "Data Source=prod8a;User Id=bugnav;Password=bugnav");
DateTime startTime = DateTime.Now;
connection.Open();
Console.WriteLine(DateTime.Now - startTime);

Normally code like this would connect to Oracle in WELL under one second.  However, under Vista, the first time I run this it takes 12 seconds!  Subsequent executions are sub-second but, if I wait 60 seconds, the following connections are back up to 12 seconds.  Very odd!

It turns out that I see this behaviour if connection pooling is enabled (and it is my default) or if the “Min Pool Size” is not specified in the connection string. The following two snippets work perfectly.

OracleConnection connection = new OracleConnection(     "Data Source=prod8a;User Id=bugnav;Password=bugnav;Pooling=false");
DateTime startTime = DateTime.Now;
connection.Open();
Console.WriteLine(DateTime.Now - startTime);
OracleConnection connection = new OracleConnection(     "Data Source=prod8a;User Id=bugnav;Password=bugnav;Min Pool Size=10");
DateTime startTime = DateTime.Now;
connection.Open();
Console.WriteLine(DateTime.Now - startTime);

I have no idea why this is happening but at least it`s easy enough to work around.

October 9, 2008

Bingo

Filed under: Fun — Jeff @ October 9, 2008 1:16 pm

We were playing Bingo at work.  I had 14 bingo cards.  It was annoying having to mark off things on each card so I opted for a computer program.  I converted my cards into digits and as the numbers came in I got instant sorted results as to which cards were winning, which numbers were left, etc.  It didn’t save much time but was way more fun!

I love Python!

cards = [
    (1,[14,10,3,5,8,23,18,28,21,16,43,40,36,39,46,48,50,57,51,62,69,72,71,65]),
    (2,[11,12,5,7,9,26,29,16,21,23,39,37,33,41,48,46,47,54,55,72,74,63,68,67]),
    (3,[15,6,10,9,13,16,26,18,23,17,38,33,39,43,46,49,59,53,58,65,62,64,71,67]),
    (4,[8,4,1,13,14,26,20,19,17,22,39,37,38,45,58,46,47,53,52,70,67,63,64,62]),
    (5,[6,12,13,10,4,30,16,23,20,24,34,43,39,44,46,50,47,51,57,75,68,74,64,69]),
    (6,[5,13,10,7,4,16,24,26,17,21,33,38,44,34,54,48,59,52,58,64,71,63,67,69]),
    (7,[15,14,12,4,6,16,25,17,28,21,37,32,44,43,49,59,52,50,53,65,71,72,73,61]),
    (8,[3,1,15,11,5,19,27,29,22,20,41,43,31,39,55,54,52,47,51,66,72,70,62,65]),
    (9,[4,7,15,13,12,26,18,24,16,21,34,35,45,44,57,53,60,56,46,75,70,64,72,63]),
    (10,[15,3,8,6,9,18,21,24,25,16,36,32,44,41,58,56,48,50,60,66,63,71,67,65]),
    (11,[2,6,13,9,5,17,26,29,25,24,37,35,34,45,59,46,56,48,55,70,68,71,69,64]),
    (12,[1,12,11,13,5,19,18,25,29,20,43,45,39,31,59,60,48,47,55,67,68,62,72,66]),
    (13,[11,12,7,3,9,16,17,19,27,23,40,44,36,35,59,46,56,54,50,72,62,63,66,65]),
    (14,[2,12,5,4,14,22,23,30,28,25,32,31,38,39,47,53,50,59,54,67,66,75,70,74]),
    ]

called = [
    25,7,18,48,44,3,19,68,13,42,32,72,26,55,30,24,14,57,50,74,51,1,36,63,52,
    8,70,38,20,64,4,65,16,34,35,
    2,47,73,41,12,46,45,60,6,33,58,29,9,11,54,
    49,10,17,53,31,69,5,56,21,67,40,59,23,71,28
    ]

res = []
for card,nums in cards:
    assert(len(nums) == 24)
    rem = list(set(nums) – set (called))
    rem.sort()
    res.append((card, len(rem), ‘,’.join(map(str,rem))))

def cmp(a,b):
    if a[1] > b[1]: return 1
    if a[1] < b[1]: return -1
    return 0

res.sort(cmp)

for r in res:
    print ‘%03s %03s %s’ % (r[0], r[1], r[2])