Archive for October, 2012

SQL DataReader problems

October 16, 2012

I may have a problem with a certain database server.

But I only see it when I use a DataReader.

The exception I get (sporadically – about 5% of the time, I think) is:

ERROR: System.NullReferenceException:
Object reference not set to an instance of an object.     at
System.Data.SqlClient.SqlDataReader.ReadColumnData()     at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32
i)     at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32
i, Boolean setTimeout)     at
System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)     at
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)     at
System.Data.SqlClient.SqlDataReader.get_Item(String name)

Note – there are no null columns in my data, and this code has worked for years.

Sometimes it happens after reading 80 records, sometimes 30, sometimes 50. We’re not talking about 10K records here.

Here is the code where the exception occurs:

isdky = dreader.Item(“sdKy”)

I read a nice blog, and converted my code to use ordinal positions:  ‘

fldProductKey = dreader.GetOrdinal(“sdKy”)


ProductKey = dreader.GetInt32(fldProductKey)

But I got the same error.

When I converted my code to get a datatable, then loop through the rows, my troubles went away. I haven’t run that in production yet, but it looks very hopeful.

This points out that I don’t quite understand the process as a reader loops and reads. It seems like it loses its schema along the way and loses track of columns.

When I get a datatable, it pulls in everything, then I close the connection. It just works more stably. We’ve seen issues on this database server in the past – but those were with writes, not read like this time.


adding a website to tfs

October 16, 2012

What didn’t work:

1) create empty Visual Studio 2010 solution

2) add an existing website to the solution. (http://localhost:81/myWebSite ) . It was port 81 because I also have Sharepoint on this pc.

What was wrong? the website could not be added to TFS.

Steps to fix:

1) add another existing library project to the solution (I needed it anyway). I think otherwise I couldn’t delete the website from the solution.

2) delete the website from the solution

3) re-add the same website, this time using the “File System” rather than IIS.

4) Check in to TFS no problems.