Even More WCF Links

Articles by Juval Lowy

Aaron Skonnard's Wiki

WCF Developer Center on MSDN

Posted: Friday, May 18, 2007 5:54:05 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 3.0 | WCF

Speaking at West Michigan Day of .Net

I will be speaking at the West Michigan Day of .Net on May 19th in Grand Rapids, MI at Davenport University.

My talk is Introduction to WCF. WCF is certainly the understated pillar of .Net 3.0. There is a ton of great content all day long, and best of all it's FREE! This is a great opportunity, don't miss out.

WM Day of .Net May 19, 2007 - I'll be there!

Posted: Tuesday, April 10, 2007 3:57:09 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Speaking | WCF

More Good WCF Links

The Server Side .Net has a good WCF link aggregation.
Posted: Wednesday, April 04, 2007 3:48:30 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
WCF

More SelfSSL Issues

I blogged previously about some issues with SelfSSL and multiple web sites. A colleague of mine, Charles Medcoff, blogs about a related problem with SelfSSL and SQL Server.
Posted: Wednesday, March 28, 2007 4:39:17 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Security | SQL Server

WCF Presentation

I am giving a presentation March 15th at the Greater Lansing User Group .net about Windows Communication Foundation.

If you have worked with web services at all you will really appreciate WCF. Come by and check it out.

Posted: Wednesday, March 14, 2007 8:45:50 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Speaking | WCF

WCF Link List

Architecture Overview

MSDN Forum

WCF Tools

Contract Versioning

Terminology

Integrating WWF and WCF

WCF Developer Home

WCF Team Blog

Posted: Wednesday, March 14, 2007 8:43:13 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 3.0 | WCF

Design with Users In Mind

We all spend lots of time delving into the technical aspects of our work, but don't forget who we are creating all these wonderful apps for. You need to design your apps to work for the users, not create apps that the users need to work to use.

Required Reading: Four Modes of Seeking Information and How to Design for Them

Posted: Wednesday, January 31, 2007 11:09:29 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Programming | Winforms

WSOD - White Screen of Death in Winforms Designer

I've seen it many times in the past, now it has a name
Posted: Wednesday, January 17, 2007 6:38:07 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio | Winforms

CopySourceAsHTML Clipboard Access Error (Blame the VPC)

I kept getting an error when trying to use CopySourceAsHTML in Visual Studio 2005. The error was that CopySourceAsHTML was unable to access the clipboard. Turns out the problem is when using it in a VPC, and the answer is here.
Posted: Monday, January 15, 2007 10:11:51 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Strange Problems | Visual Studio

Casting Text Data to Members in a Business Object via Reflection

I have a pipe-delimited text file that I am parsing and using to fill a collection of custom business objects. Instead of hard-coding the bits of each pipe-delimited line, I am using an XML file to map data items in the file to object members, like this XML fragment:

<Field>
    <Name>NAMID</Name>
    <Location>0</Location>
    <MapsTo>MemberId</MapsTo>
    <IsRole>false</IsRole>
</Field>

After parsing and matching the data element to the proper member name, I call this function:

public void SetDataMemberValue(string memberName, Member member, string data)
{    // get an instance      
     // of that object's type.
     Type objectType = member.GetType();
     PropertyInfo[] properties = objectType.GetProperties();
     foreach (PropertyInfo property in properties)
    {         if (string.Equals(property.Name, memberName, StringComparison.OrdinalIgnoreCase))
        {
            object[] args = new object[1];
            args[0] = data;
            object result = null;
 
            if (property.PropertyType == data.GetType())
            {
                //The type of the property matches the data's type
                result = data;
            }
            else
            {
               result = property.PropertyType.InvokeMember("Parse", BindingFlags.InvokeMethod, null, result, args);
            }
 
            if (result != null)
            {
                property.SetValue(member, result, null);
            }
        }
    }
}

The tricky bit is the InvokeMember call, which is casting my string to the appropriate type for the property. Of course this is they stylized version of the function, I removed the try-catch bits to make it smaller and readable for the acutal function. You should wrap the InvokeMember call with a try-catch as Parse methods can fail quite hard.

Posted: Monday, January 15, 2007 9:27:13 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

Vista and Visual Studio 2003 - Not Supported

Now that Vista has gone RTM, lots of us are trying to decide when to upgrade. Here is something I have not seen much mention of:

Visual Studio 2003 is not supported in Vista.

This is going to hold back adoption on my work machine. I'm a consultant, I have to do work on whatever platform the client is using, which unfortunately is VS 2003 sometimes. Is VS 2003 going to be relegated to life in a virtual machine from now on?

Posted: Thursday, November 09, 2006 7:42:56 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

Vista and Visual Studio 2003 - Not Supported

Now that Vista has gone RTM, lots of us are trying to decide when to upgrade. Here is something I have not seen much mention of:

Visual Studio 2003 is not supported in Vista.

This is going to hold back adoption on my work machine. I'm a consultant, I have to do work on whatever platform the client is using, which unfortunately is VS 2003 sometimes. Is VS 2003 going to be relegated to life in a virtual machine from now on?

Posted: Thursday, November 09, 2006 7:42:52 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

Method for Installing WSS 3.0 Beta2 TR as Slipstream

From JOPX on SharePoint 2007.

Also, the WSS-only install for WSS 3.0 is available here.

Posted: Monday, October 23, 2006 7:44:43 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SharePoint

Method for Installing WSS 3.0 Beta2 TR as Slipstream

From JOPX on SharePoint 2007.

Also, the WSS-only install for WSS 3.0 is available here.

Posted: Monday, October 23, 2006 7:44:14 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SharePoint

ASP.Net Single Sign On - Same Domain

This post in the ASP.Net forums has been the best method for me to make a single-sign on work across different sites in the same domain.

You have to set the machine key in the web.config of all sites even on the same physical box.

Posted: Wednesday, October 11, 2006 6:11:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Security

A List of Visual Studio 2005 Hotfixes

A Google search of hotfixes.
Posted: Thursday, August 24, 2006 8:33:33 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

A List of Visual Studio 2005 Hotfixes

A Google search of hotfixes.
Posted: Thursday, August 24, 2006 8:33:27 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

MCMS 2002 Error: The CMS Server license has expired

OK, now that would seem like a pretty straightforward problem, but really it was something else altogether.

Currently I am writing a helper app for MCMS (Microsoft Content Management Server) 2002 to migrate files from another CMS to MCMS. I am using C# and PAPI calls. Everything was fine on the development server. When I moved the app to the staging (QA) server to perform the migration there (you can't use PAPI remotely), the app got an exception the moment it tried to connect to MCMS: "The CMS Server license has expired". Of course immediately I thought the obvious. After a little digging I found this information in the FAQ implying that I didn't have the proper permissions. I had the server admin elevate my permissions and immediately the problem was solved.

The lesson here: "Develop with least privileges!" It will save you headaches later.

Posted: Wednesday, August 02, 2006 8:13:44 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
MCMS

Speaking at the Visual Studio 2005 Experience on July 28th

I will be presenting sessions at the Speaking at the Visual Studio 2005 Experience on July 28th. My sessions will be on Visual Studio 2005 – New Features inside the Microsoft Across America truck. There are still spots available for some of the sessions that day. Sign up before it is too late!
Posted: Monday, July 10, 2006 5:51:46 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Speaking | Visual Studio

How ADO.Net 2.0 Batch Updates Really Work

An excellent post by Pablo Castro of  the ADO.NET team explaining the mechanics of how batch updates work with ADO.NET 2.0 and Sql Server 2005.
Posted: Friday, July 07, 2006 3:50:09 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SQL Server

Don't Re-Invent the Wheel - The .NET Developer's Guide to Identity

Learn how to leverage Active Directory in your .Net apps:

The .NET Developer's Guide to Identity

Posted: Monday, June 26, 2006 7:08:41 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Security

A BCL Method to Set a String in Title Case in C#

No need to create a function yourself or reference a VB library: A great post by Rick Strahl:

public static string TitleCase(string input)

{

      return System.Threading.Thread.CurrentThread.

             CurrentCulture.TextInfo.ToTitleCase(input);

}

Posted: Tuesday, May 23, 2006 12:11:44 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

VSTO Action Pane Closing

When creating VSTO documents that use an Action Pane, the Action Pane gets "lost" if you open another non-VSTO document. The Action Pane is hidden by the different document (as it should), but when you switch back to the original VSTO document, the Action Pane does not automatically re-open itself. This can be fixed by handling the ThisWorkbook_WindowActivate event. In this event we can check the state of the Actions Pane and re-display it if necessary:

private void ThisWorkbook_WindowActivate(Microsoft.Office.Interop.Excel.Window Wn)
{
    if (!Globals.ThisWorkbook.ActionsPane.Visible)
    {
        Globals.ThisWorkbook.ActionsPane.Visible = true;
    }

    if (!ThisApplication.DisplayDocumentActionTaskPane)
    {
        ThisApplication.DisplayDocumentActionTaskPane = true;
    }
}

Posted: Tuesday, May 16, 2006 5:48:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

Read and Learn

An awesome post by Jessica Fosler about finding memory leaks.
Posted: Tuesday, May 09, 2006 12:19:34 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Performance

Another VSTO ListObject Bug

With extensive use of the ListObject in an Excel VSTO project, I have identified a second actual bug in the ListObject. This one also has to do with pasting data like the previous bug I posted about, but this time data is being lost instead of created erroneously.
Posted: Thursday, April 20, 2006 9:52:24 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

Free .Net Event in SE Michigan: Day of .Net

I just learned about a FREE .Net training event being held in Ann Arbor, MI on May 13th, 2006: Day of .Net! Check out the agenda at the site.

It is a one-day event advertised as a One Day Conference on all things .NET by Developers for Developers. Lots of great speakers, starting with Mark Miller of Mondays fame, and lots of great local .Net experts, including great guys like Aydin Akcasu, Nino Benvenuti, Dustin Campbell, Jason Follas, Dave Giard, Charles Stacy Harris III, Darrell Hawley, Jim Holmes, Josh Holmes, John Hopkins, Greg Huber, Paul Kimmel, Alex Lowe, Drew Robbins, Martin Shoemaker, and Bill Wagner.

Posted: Thursday, April 06, 2006 8:32:25 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback

ASP.Net Windows Authentication and 401.2 Errors

I am working on an ASP.Net app that usesWindows authentication for users. I have a certain section of the app, the "Administration" set of pages that I want to exclude from certain roles of users. This is easy using a web.config file, but the unauthorized users get an ugly default 401.2 error page. I would like to have a custom page for that, and surpisingly there was not a ton of information out there on how to do it. In fact, more often than not the answer was "It can't be done."

I did find an acceptable answer in the forums at aspfree.com. Essentially the solution is to handle the Application_EndRequest event in the global.asax and check the status code and authentication of the user. Here is my version:

void Application_EndRequest(object sender, EventArgs e)
{
    if (Response.StatusCode == 401 && Request.IsAuthenticated && Request.Url.AbsoluteUri.Contains("Administration"))
    {
        Response.ClearContent();
        Server.Execute("../NoAccess.aspx?id=Administration");
    }
}

 

I don't believe this method will work with Forms Authentication, I ran across plenty of posts saying that it works differently.

Posted: Tuesday, April 04, 2006 7:28:29 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Security

Free Contract First Tool - WSCF

Thinktecture has released a Visual Studio 2005 compatible version of their free WSCF tool. WSCF is a Schema-Based Contract-First Web Services code generator. It allows you to design the messages, interfaces and data for contract-first style web services, acting as a replacement for XSD.exe and WSDL.exe. We have been using XSDObjectGen to do something similarly, but WSCF looks like it is much more flexible. For one thing, it generates collections using generics as List<T> instead of the non-type specific ArrayList that XSDObjectGen creates or the even more simplistic arrays that WSDL.exe creates. If you are using .Net 2.0, this is a great step forward for contract-first tools.
Posted: Friday, March 03, 2006 3:48:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

List Databinding Performance With DisplayMembers and ValueMembers

My copy of MSDN magazine arrived last night, and I read the article Practical Tips For Boosting The Performance Of Windows Forms Apps. Good read. Anyway, I was shocked to find out that I have been databinding lists improperly ever since I have been using .Net. I frequently wrote my code like this:

//Bad Code
combobox.DataSource = datatable;
combobox.DisplayMember = "State";
combobox.ValueMember = "Id";

//Good Code
combobox.DisplayMember = "State";
combobox.ValueMember = "Id";
combobox.DataSource = datatable;

Apparenly, order matters very much. In the first example, the combobox binds using the DisplayMember, then rebinds when updated with the ValueMember. In the second example, the binding only happens once.

In our current app, we have two lists that contain thousands of items that need to be bound, so we are binding them during the startup process so the user won't wait when requesting that data. The startup time was reduced by just under 40% by changing the order of the code for binding.

Posted: Wednesday, February 15, 2006 4:36:53 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | Performance | Winforms

Adding Images to CommandBarButtons in VSTO

An old VSTO 2003 post by Kathleen McGrath about how to add images to a CommandBarButton. It still works in VSTO 2005. The example uses the AxHost object to convert bitmaps to stdole.IPictureDisp types for Office toolbars.
Posted: Monday, February 13, 2006 10:35:30 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

The Clipboard Ring Rules!

Checking amongst the group of developers I work with, no one knew this trick. I read about it yesterday here. The feature is called the Clipboard Ring, and it is in both Visual Studio 2005 and 2003. Using Ctrl+Shift+V lets you cycle through the last 10 items you have placed on the clipboard. The command is also found in the Edit Menu in and in the Toolbox in VS2003.
Posted: Friday, February 10, 2006 4:52:20 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

ADO.Net 2.0 Presentation on January 20th

I will be giving a presentation at a Microsoft Developer Care event at their offices in Southfield, MI on January 20th. The event is sponsored by New Horizons and I will be talking about What's New in ADO.Net 2.0. There will be two other talks as well, see the agenda for details.
Posted: Sunday, January 29, 2006 6:26:58 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | Speaking

VSTO Excel ListObject Bug

I found an actual bug with the VSTO ListObject in Excel and insertions of data. See this post on the MSDN forums for details.
Posted: Wednesday, January 25, 2006 6:09:38 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

Generics and Enums or Enum.TryParse

I have a case where the user is entering strings into the application, and I have to match that string with the values from a given Enum. Normally that is not too difficult of a task, just convert the enum item to a string and compare, but in this instance I have a bunch of enums to do this with, so I didn't want to write a separate function for each enum type. So I figured generics might provide a solution and here is what I came up with, which is loosely based on the idea of int.TryParse:

/// <SUMMARY>
/// Takes a string that represents an enum member 
///   and returns the enum member
/// </SUMMARY>
/// <TYPEPARAM name="T">An Enum</TYPEPARAM>
/// <PARAM name="input">
///  The string that is the enum member name, case does 
///    not matter
/// </PARAM>
/// <PARAM name="returnValue">
/// The value from the enum that matches the string, or the 
/// first value of the enum /// </PARAM>
/// <RETURNS>
/// True when there is a match, false when not
/// </RETURNS>
/// <REMARKS>
/// - When no match the first item in the enum is returned
/// - The where clause attempts to constrain the input of T 
/// at compile time to be an Enum
/// </REMARKS> private bool GetEnumValue<T>(string input, out T returnValue)
where T : struct, IComparable, IFormattable, IConvertible { if(Enum.IsDefined(typeof(T), input)) { returnValue = (T)Enum.Parse(typeof(T), input, true); return true; } else //input not found in the Enum, fill the out parameter
// with the first item from the enum
{ string[] values = Enum.GetNames(typeof(T)); returnValue = (T)Enum.Parse(typeof(T), values[0], true); return false; } }
Posted: Wednesday, December 07, 2005 7:58:05 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

Awesome IIS Resource

IISToolshed - thanks to Paschal for pointing it out.
Posted: Thursday, December 01, 2005 7:23:36 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
IIS

Comboboxes and Double-Clicks

The standard combobox control doesn't support the double-click event, as it is actually a combination of more than one control itself. In my case, I am using the combobox in simple mode with a textbox at the top and a permanently open list directly below the textbox. I needed for the listbox below to respond to the user double-clicking a list item. I found a great solution in a Usenet post by Jacques Bourgeois in microsoft.public.dotnet.framework.windowsforms.controls. Essentially the code simulates a double-click using the single-click event and a timer control.

Declare a timer control in your class, and in the load event of the form instantiate the timer set the interval of the timer to the interval of the double-click as set in the user's system:

this.comboDoubleClick = newTimer();

this.comboDoubleClick.Interval = SystemInformation.DoubleClickTime;

In the event handler for the timer, set the code to stop the timer:

this.comboDoubleClick.Enabled = false;

Add code to the single-click event handler to handle the double-click. When the event handler fires, if the timer is not enabled, start the timer (the first click). If the timer is enabled, a previous click has occurred within the system set interval for a double-click. This must be the second click of the double-click, so do whatever you needed the double-click to do and then disable the timer for the next single-click event.

private void Combo_MouseClick(object sender, MouseEventArgs e)
{
   
if (this.comboDoubleClick.Enabled == true)
    {
       
//Do double-click work here
       
this.comboDoubleClick.Enabled = false;
    }
   
else
   
{
       
this.comboDoubleClick.Start();
    }
}

Posted: Thursday, November 10, 2005 6:01:28 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | Winforms

C#, VSTO 2005 and ActiveCell.Offset

Just a quick tidbit about using the Excel object model and C# in VSTO 2005. ActiveCell.Offset (as we know it in VBA, and even VB.Net) is not there in exactly the same way with C#. The syntax for C# is:

ActiveCell.get_Offset(1,1).Value2 = 22

And of course you need to use Value2 instead of Value, it's not like there is any choice there anyway.

Posted: Friday, October 21, 2005 10:18:15 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

SelfSSL and Site ID

SelfSSL is a tool found in the IIS 6.0 Resource Kit. It allows you to generate SSL certificates for a development environment. In all the instructions for using SelfSSL, it describes one of the parameters as "Site ID", where the default value=1, which is the default web site installed on the computer. The Site Id parameter is essentially telling SelfSSL which web site to install the certificate into. Well, if you have multiple web sites, then the default site id is useless. You need the Site Id of the web site where you want the certificate installed. Of course the documentation does not spell this out, and as a non-Admin the Site Id was not an intuitive term for me. But I found that there is a script you can run from the command-line called iisweb.vbs using the /query switch. That will tell you the Site Id. Seeing that, then I realized that the IIS log file folders (in windir\System32\logfiles\) are named according to the Site Id.

Anyway, creating a second certificate for a different site on the same IIS using SelfSSL messes up the SSL cert of first site. This is a known issue apparently, and David Wang has a great post on this problem. The comment further down by Paul Carrig is most useful, as he points out there is a workaround for the SelfSSL and multiple site issue. So I actually found two workarounds:

  1. The technique described by in the aforementioned post:
    1. Install the cert in the first site
    2. Export it to a .pfx file
    3. Install the cert in the second site
    4. Remove the cert from the first site
    5. Re-Import the cert to the first site using the .pfx file

      or
  2. Install the cert in the first site, and export it to a .pfx file. Then import that to the other sites. The down side to this is that the certificate is even less valid for the second sites as now it has an untrusted publisher (me!) and the site name is not a match. The prompt is essentially the same, but in our case one site contains web services which will throw an error if the prompt comes up at all (as it should). The workaround for that is to install the certificate on the client computers as well, which is an acceptable problem for a development enviroment.
Posted: Monday, August 08, 2005 8:27:20 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
IIS | Security

Batch execute SQL files in a directory

Having to excecute hundreds of .sql files in an environment without port 1433 open led me to this nugget of a Usenet post: How to execute multi-file.

Here is the gist of it, the command line for executing all those .sql files with osql:

FOR %i IN (*.sql) DO OSQL -n -U sa -P sapassword -d databasename -i %i

I am sure I could have merged them all into one file or made some sort of batch vbs, but this did the trick nicely.

Posted: Monday, July 25, 2005 5:21:07 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SQL Server

Whidbey Beta 1 to Beta 2 Migration with Typed Datasets

Today we are migrating my project from Whidbey Beta1 to Beta 2 (if you know why this is happening today, go ahead and laugh with us), and our biggest hurdle so far is Typed Datasets.

We used dozens of XSD schemas to create typed datasets. Of course, Beta 2 no longer gives a menu option for creating a typed dataset directly from a schema (see this post in the Fedback Center for Visual Studio). The prospect of converting to the Dataset type of schema was daunting, and moving to the command line for xsd.exe was not going over so well either.

We did discover, however, that you can still generate the dataset using the IDE. In the properties of the XSD file, you can set the custom tool to MSDataSetGenerator. Then you can right-click the XSD file and choose Run Custom Tool. The IDE generates the code for the dataset. Whew!

Posted: Friday, July 01, 2005 4:25:55 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

Select Distinct in a DataTable (The Whidbey Version)

In my last post I described a “Select Distinct“ function for a datatable. This is a whole lot easier using Whidbey. You can get a distinct table based on a column in the DefaultView of the datatable:

DataTable d = dataSetName.dataTableName.DefaultView.ToTable(true, new string[] { "ColumnName" });

Posted: Wednesday, May 25, 2005 7:06:56 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | ADO.Net

Select Distinct in a DataTable

I needed to perform a “Select Distinct“ on a datatable, not in the database, for binding to a listbox. Found a good solution here. Modified it according to one of the comments to use a hash table so sort order won't matter. Here is my version of the function:

private DataTable SelectDistinct(DataTable sourceTable, string sourceColumn)
{
    DataTable result = null;
    try
   
{
        result =
new DataTable();
        result.Columns.Add(sourceColumn, sourceTable.Columns[sourceColumn].DataType);
       
Hashtable ht = new Hashtable();
       
foreach (DataRow dr in sourceTable.Rows)
        {
           
if (!ht.ContainsKey(dr[sourceColumn]))
            {
                ht.Add(dr[sourceColumn],
null);
               
DataRow newRow = result.NewRow();
                newRow[sourceColumn] = dr[sourceColumn];
                result.Rows.Add(newRow);
            }
        }
       
return result;
    }
   
catch (System.Exception ex)
    {
       
ExceptionManager.Publish(ex);
       
return null;
    }
   
finally
   
{
       
if (result != null)
            result.Dispose();
    }
}

Posted: Wednesday, May 25, 2005 6:26:46 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ADO.Net

Getting Started with the User Interface Application Block

There is an excellent “Hello World” article  for getting started with the UIAB at CodeProject by Roy Clemmons. If you have checked the docs that come with the block, you can appreciate a simplistic example. The block is a powerful piece of code, but you have to get started before harnessing the monster. I had a very difficult time distilling the example code from the block down to something simple that worked. The article from CodeProject did the trick.
Posted: Tuesday, April 12, 2005 4:51:36 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

Virtual PC SourceSafe Network Problem

We have been using Virtual PCs to host a separate development environment. Some of the team members have been having sporadic network issues with SourceSafe on the Virtual PCs. They were unable to get all of the projects involved down to the Virtual PC without getting a “Network Not Found” error. Eventually they would get all the files, but it was clearly not the best situation.

The Virtual PC image was sysprepped before distributing it, to avoid network problems. Unfortunately, that is not completely the case. Sysprep does reset the MAC address on the Virtual PC, but it apparently happens when sysprep runs, not when the user is re-setting up the PC. After distributing the image, the subsequent users still had the same MAC address. This was causing network problems when more than one person were using the Virtual PCs at the same time. The problem manifested itself mostly with SourceSafe, especially when there was a large change and multiple users were getting all the latest files at the same time.

At least the solution was simple once we realized that the MAC address was the issue (thanks to an astute network admin who had noticed some problems with a particular MAC address on one of the switches). In the .vpc file (it's XML), there is an entry for ethernet address. It contains the MAC address the Virtual PC uses. If you remove the data from the tag, leaving the empty tags, Virtual PC will auto-generate a new MAC address the next time it starts up. Since that change the “Network not Found” error has disappeared.

Posted: Wednesday, February 23, 2005 1:54:57 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Strange Problems

Data Access Application Block v2 Bug

Mark Brown posted his fix for a bug in the FillDataSet method of the SqlHelper in the Data Access Application Block. The problem occurs when trying to use the FillDataSet method to fill a typed dataset that contains more than two tables. It works great for the first two, not at all for the subsequent tables.

I gave Marks\'s fix a try, but it still didn't fix the problem for me. I did more digging and found a slightly different fix straight from the authors of the DAAB on the GotDotNet workspace for the DAAB. The fix is in the bug section (direct links don't seem to work) This cleared up my problem right away. Of course, the bug is fixed in version 3+ of the DAAB. If you are like me, the MSDN site has been my source for the code for the application blocks, and of course there is only 2.0 on the site.

I did not realize they were on version 3 of the DAAB. The authors have added support for an abastract factory to make the SqlHelper ADO.Net provider independant. I don't know about the rest of you, but the only projects I have ever had to change the database provider on have been Access upgrades. I have never had to move a database back end, say from SqlServer to Oracle. Is it more common than I realize?

Posted: Thursday, January 27, 2005 4:28:15 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | ADO.Net

Reloading for the New Year

After a harried development and delivery of a good sized Software Spec document to a client before the holidays, I have tried again to load XP SP2 on my laptop (hp compaq nx5000) without success. Despite updating all the drivers and the ROM before loading SP2, I still get blue screens after the profile loads, but not every time. The plan now is to wipe it out and start from scratch.

Posted: Wednesday, January 05, 2005 7:58:06 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Strange Problems

Securing the Connection String with the Machine Key

d.code asks about securing connection strings. If you are willing to deal with a little unmanaged code, you can use the machine key or a user key via Data Protection API (DPAPI) functions instead of hiding your key somewhere. I first heard about the machine key at a Microsoft Security Summit that was touring around the country last spring. I based my work on this example, and a relevant MSDN article. The upside is that you do not need to maintain your own key somewhere, the downside is that any application run on the computer could decrypt your string, and that an encrypted string cannot be passed between computers (or users if you go that route), so you have to create the encrypted strings during deployment and have access to run an executeable on the production computer during deployment.

I created a small Winforms program that I run during deployment to encrypt my connection strings using the machine key. It just has two text boxes and two buttons for encrypting and decrypting strings. Once the deployment is done the exe is removed from the production machine. If someone compromised the box, they would have to know you used DPAPI (which they could only determine by spending the time to decompile your assembly) and have their own exe ready or create one to decrypt the strings. A little obfuscation on your code would contribute to the security in this situation.

Posted: Friday, November 12, 2004 1:26:46 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Security | Winforms

OneNote

I am getting to know OneNote now that I am a laptop user. It has been very useful in meetings and very good for organizing my thinking/working, but I learned a couple new things last week that are worth noting:

  • You can capture audio as a note. I am finding this very useful when listening to .NetRocks shows and I want to save a small part of it that I can get back to quickly. I can add my own text comments right there as well as relevant URLs, etc. Just change the audio input source to Wave Out Mix in the Options dialog box.
  • You can capture screenshots into a note (Insert Menu -> Screen Clipping). This is only in OneNote Service Pack 1. I am currently in the design phase of an application and this is very handy. I can take a screenshot into the note and then share the note in meetings with the team. You can even do this when OneNote is closed using the OneNote icon in the system tray.
Posted: Monday, October 25, 2004 4:13:59 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office

.Net Framework Service Pack 1 Postback Problem

I applied the .Net Service Pack 1 to a Windows 2003 server last night and the web application served from it stopped submitting postbacks. When the login page was sent to the client (IE 6 on XP, 98, and 2003 that's all I had to test with at the time), the javascript was preventing the postback from the submit button. The validators all worked, but the page just would not post back. Click the button...nothing. The development machine with XP Pro and the Service Pack 1 did not have the same problems. I ended up rolling back the patch to get things working as it was late and I didn't find any solutions right away, but this morining I found some other possible workarounds.

There is a discussion of the problem and several potential solutions on the Channel 9 site.

Posted: Sunday, October 03, 2004 1:00:42 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 1.1

SharePoint Web Part Template for Visual Studio Install Problem

I tried to install the SharePoint web part templates today and got this error:

"Visual Studio .NET must be installed before you can install the Web Part Templates for Visual Studio .NET."

But of course, Visual Studio is installed. I found two answers to the problem on the Usenet:

Add Missing Registry Keys

Reinstall Visual Studio

Along the way I also discovered that you must either have the Microsoft.SharePoint.dll on your machine or on a share you can access in order for the install to proceed.

Posted: Thursday, September 09, 2004 6:22:56 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SharePoint | Visual Studio