Skip to main content

164 posts tagged with "tech"

View All Tags

C# Extension Methods for IDataReader

· 2 min read

My team often starts Tuesday morning status meetings with a round of win/learn/fun - a team-building exercise where each person gets to mention an exciting "win", something they learned in the last week, or just something fun. Several weeks ago someone brought up C# Extension Methods as a learn. I could see the potential, but I didn't immediately think of any practical examples.

SSIS Crashes When Editing OLE DB Source

· One min read

Problem

SSIS 2005 (actually, Microsoft SQL Server Business Intelligence Studio) crashes every time you click on an OLE DB Source to edit it. (there are probably similar errors for OLE DB destinations).

Solution

oddly enough, synchronize a few DLLs:

Version of the assemblies msmdlocal.dll and Msmgdsrv.dll must be the same of the ones installed into "%ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\" and the ones installed into "%ProgramFiles%\Common Files\System\Ole DB" location.

If it is not same for any or both of these DLLs, then replace the ones in PrivateAssemblies with the ones from ole db.

Hat tip: Calculation tab not working — SQL Server 2005 Analysis Services

Securely Accessing Network Resources in an ASP.Net Web Service

· 2 min read

Problem

You have an ASP.Net web service/site that needs to access network resources, and IIS is running in a service account that you do not want to have access to those resources.

Solution

Create a custom network account and setup a separate application pool. Microsoft article How To: Create a Service Account for an ASP.NET 2.0 Application outlines some pros/cons and gives a few alternatives, as well as giving the basic instructions. However, I found that these instructions had to be modified with inclusion of a few extra security rules. Steps:

TDD - Scenario for Red, Green, Refactor

· One min read

Here's a really dumb scenario that will illustrate a point about the usefulness of the "red, green, refactor" approach to testing and coding. Here's the functionality - need to test whether or not a string has a value other than 1. Let's say I write a method before any tests:

Closing A Cursor in SQL Catch

· One min read

Problem

In a T-SQL script, an exception occurs while a cursor is open, resulting in the cursor never being closed. But, the exception handling wraps the entire script, not just the cursor, so there is no guarantee that the cursor will be open if/when the CATCH statement is reached.

Solution

query the sys.syscursors view to see if the cursor(s) in question is still open:

Think For One ... Second

· One min read

What's wrong with this code? There are unnecessary lines. So? Why care about unnecessary lines? Because it shows that the programmer was not really thinking about what he was doing.

MyObject obj = someList.Find(delegate(MyObject test)
{
if (test.Id.Equals(packageId))
{
return true;
}
else
{
return false;
}
});

Unit Testing Functions That Call Microsoft Enterprise Logging

· 2 min read

Problem

you have a method that logs a message using the Microsoft Patterns & Practices Enterprise Library Logging Block, and you would like to write an automated unit test for it in NUnit (or Team System — solution is easily adapted). Logging to a flat file doesn't work; the file is still open when you try to read it to verify that the message has been logged. Logging to the database doesn't work; it seems the log isn't written to the database immediately. And so forth. Is there an in-memory way of reading the logged message?

Sub classing for automated testing

· 2 min read

A few months after I first purchased it, I am still reading xUnit Test Patterns. Been reading a few pages every day - now on page 590 with a few hundred to go!

I have finally arrived at the point where the author describes the pattern Test Specific Subclass (TSS). This is a pattern we have used extensively in our testing at the office, so that we can access protected methods in our classes. However, we stumbled upon it on our own, well before reading anyone else's suggestions on how to apply it. That's the nature of patterns for you.

Automatic Properties in C# 3.0

· One min read

We just upgraded our servers to support .Net 3.x, so at last I'm able to start migrating some of my code. I haven't taken a close look at all the features available yet, but one that caught my eye and initially excited me is automatic properties. However, I had two conflicting reactions:

  1. This is great, I don't have to create a private field and write getter/setter in a public Property anymore.
  2. But then what's the point of not just creating a public field and using it directly?

Well, this article addresses a primary benefit: this facilitates refactoring. If, for instance, we find later on that we need something more advanced than a simple get or set statement, then we can add it without breaking the interface. I'm sold.

safnet logo