Blog Home  Home Feed your aggregator (RSS 2.0)  
Implements IVillage - Wednesday, June 13, 2007
It takes a village to keep up with .Net
 
 Monday, May 21, 2007

We took a pretty good hit at work a couple of weeks ago.  We lost one of the good guys to another companyPaul's leaving because he found himself one of those opportunities that is so well fit for him that it probably only comes along once in a lifetime.  Paul reads many of the same Blogs I do.  He reads one blog that I don't read and happened to read this interesting post.  After submitting his resume and some discrete omissions of the truth (Paul is ready for politics) to his co-workers, we get a resignation

My time with Paul has definitely increased my knowledge and understanding of some XP principles, repeatable build processes and source control.  Best of Luck to him and his family!

Monday, May 21, 2007 6:09:01 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [1]    | 
 Tuesday, May 15, 2007

David McNamee will be presenting on Windows Workflow on May 16th @ 6:30 PM.  The Sapce Coast Credit Union Building as usual.  See http://www.scdnug.org for details.  Hope to see everyone there.

Tuesday, May 15, 2007 10:55:41 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]    | 
 Monday, April 09, 2007

I was implementing some data access code for a personal project using the Enterprise Library's Data Access Application Block (DAAB).  I was running some code that checked for the existence of a row prior to issuing an insert.  Here is the original code:

SqlDatabase db = DatabaseFactory.CreateDatabase("mainDB") as SqlDatabase;

string sqlCommand = "ar_GetArrestReportItemByCaseNumber";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

db.AddInParameter(dbCommand, "reportId", DbType.Int32, reportID);
db.AddInParameter(dbCommand, "caseNumber", DbType.String, caseNumber);

IDataReader dataReader = db.ExecuteReader(dbCommand);

exists = dataReader.Read();

After running through on some test data, I gave it a run against some real world data.  And it worked fine until the data's batches exceeded 100 rows.  Then I got the error message:

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

I checked SQL Manager and saw 100 connections / processes accessing the table in question.  I am using the DAAB.  The Database class is supposed to take care of this sort of thing for me.  There was a bug in VS 2003, but this was fixed in VS 2005.  Where is the connection being left open... the DataReader.  I forgot to close the DataReader.  I promptly re-educated myself on some ADO and IDisposable.  Whenever an object implements IDisposable, there is probably a good reason for it... like say... releasing a connection object back to the connection pool.  Corrected code and much better performance:

SqlDatabase db = DatabaseFactory.CreateDatabase("mainDB") as SqlDatabase;

string sqlCommand = "ar_GetArrestReportItemByCaseNumber";
using (DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand))
{
   db.AddInParameter(dbCommand, "reportId", DbType.Int32, reportID);
   db.AddInParameter(dbCommand, "caseNumber", DbType.String, caseNumber);

   using (IDataReader dataReader = db.ExecuteReader(dbCommand))
   {
      exists = dataReader.Read();
   }
}

Moral of the story... if IDisposable is implemented, chances are you should call it.

ADDENDUM
----------
For those who are not familiar, IDisposable is an interface for the implementation of the Dispose Pattern.  This is very useful in programming languages that have Garbage Collection (ie. .Net).  When you have Garbage Collection, you have what is called a non-deterministic destructor.  In other words, when you are done using an object, you have no idea when it's resources will be freed.  Garbage Collection occurs at an interval that is determined by the system.  By implementing IDisposable, you ad a Dispose method to your class where high contention resources can be freed (ie. File Handles, Database Connections, etc.).  The implementing of IDisposable signals the user that there is something valuable to be cleaned up ASAP that cannot wait for Garbage Collection.  So, even if Dispose is called, the Garbage Collector will still clean up the object's resources eventually.  But in the mean time, all of the high value resources have been released.

Monday, April 09, 2007 10:49:49 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]    | 
 Wednesday, April 04, 2007

I wanted to share this bit of SQL wisdom I picked up a few months ago on the ASP.Net forums (http://forums.asp.net). Let's say you have an orders table and you have an orderDate column that contains the Date & Time of the order.  If you wanted to create a query to select all orders made yesterday at any time, I cameup with this working (if not long winded) method:

 Where orderDate = CAST(MONTH(DATEADD(day, - 1, GETDATE())) AS varchar) + '/' + CAST(DAY(DATEADD(day, - 1, GETDATE())) AS varchar) + '/' + CAST(YEAR(DATEADD(day, - 1, GETDATE())) AS varchar))

I was treated to an extreme stream lining of this on the forums.  The resulting query was:

Where orderDate >= convert(Varchar, Getdate() -1, 101) And orderDate < convert(Varchar, Getdate() , 101)
 
The use of convert with the right format number negates a lot of work and is much easier to read.
Wednesday, April 04, 2007 9:32:33 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [2]    | 
 Tuesday, March 27, 2007

Wow.  The General Manager of the Microsoft Developer Division in Melbourne, FL.  It was quite an enjoyable presentation.  Scott typed away at the demo like he still was slugging code with the rest of us in the trenches.  Everybody really appreciated Scott taking the time out of his schedule to come over from DevConnections in Orlando.  Scott arrived just in time because somebody told him would only take 45 minuets to drive the Melbourne-Orlando gauntlet in rush hour.  I wasn't paying attention, but I think he implicated one of the local evangelists.

The presentation covered all things Orcas.  Scott covered lots of topics in a marathon 2 hour presentation.  He enthusiastically  made LINQ dance to the oohs and ahhs of the assembled crowd.  Another big pleaser was a simple demo of the IIS configuration items that moved into the web.config file.  The presentation had a couple of the prerequisite CTP crashes for which Scott took a little good natured ribbing.  When an ASP.Net error page popped up in his browser mid demo, he was jeered - "Hey, I have that page in my program too!"  When demonstrating the ability of IIS7 to track long running/hanging pages, Scott said this might be useful if we knew anybody who wrote software with bugs in it (wink wink). 

It was a record crowd for the user group with strong attendance from ONetUG members.  Looking forward to a good year of speakers.

 

Wednesday, March 28, 2007 5:35:23 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]    | 

Quick tip for those putting alternate user names and passwords.  When you export your bindings file, BizTalk 2006 replaces the password for the user credentials with a VT_NULL inside the <TransportTypeData> element:

&lt;Password vt="1" /&gt;

Be careful, that vt="1" mean NULL, or in other words - no password.  So when you do this:

&lt;Password vt="1"&gt;mysecret&lt;/Password&gt;

You might as well do nothing.  When the file receive adapter imports these bindings, it will not set a password.  However, the send adapter doe snot seem to care and will set the password fine.  Regardless, the proper form is to specify VT_BSTR attribute in the Password element:

&lt;Password vt="8"&gt;mysecret&lt;/Password&gt;

You can find this documented in the Biztalk binding file documentation:

Configuration Property Variable Types

File Adapter Configuration Properties

Tuesday, March 27, 2007 8:25:34 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]    | 
Copyright © 2010 Christian M Loris. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.