Thursday, April 23, 2009

.Net Code Converters

Once in a while I find a useful code sample written in VB.Net. Today I needed some code that essentially does the work of OracleCommandBuilder.DeriveParameters, but with some modifications. I found a code sample for just such a class, posted by someone named David Browne at http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-ado-net/116/Returning-Stored-Procedure-Parameters. Unfortunately, Mr. Browne's code is in VB.Net, whereas I'm in the middle of writing an app in my preferred language, C#.

The best code converter I've found thus far is from Telerik at http://converter.telerik.com. What's key about this converter is that it gives you very helpful translation error reporting for the inevitable copy-and-paste glitches that accompany any sizeable snippet gleaned from the web, such as inappropriate link breaks.

Saturday, January 3, 2009

Edit and Continue vs. Lambda Expressions

Microsoft giveth and Microsoft taketh away. One of the amazing gifts of .Net 3.5 is lambda expressions. Once you start using them, it's hard to stop. Unfortunately, lambda expressions are not compatible with another innovation: Visual Studio's Edit and Continue (or EnC). If you try to edit code with lambda expression while debugging in VS you get the following:

"Modifying a 'method' which contains a lambda expression will prevent the debug session from continuing while Edit and Continue is enabled."

According to this post, EnC is also incompatible with anonymous methods, a limitation present since .Net 2.

Friday, August 15, 2008

Data Dude Has Trouble Diffing Views, Stored Procedures, and Functions

Data Dude's schema compare feature is a technical wonderment . . . when it works. It seems to be fine when comparing databases to each other. Unfortunately, when comparing a data dude "project" to a database created independently from Data Dude, Data Dude seems think that there is extra whitespace in its cached copy of the ddl for the database's view, function and stored procedure ddl. What's going on here? It turns out that Data Dude is very picky about what is considers properly written ddl definitions. Data Dude wants you to allow it to write all the ddl to the database! Thus if you have created your database objects in SQL Server Management Studio you'll have to resync going from the Data Dude project back to the database after importing the schema from the database--a full round trip. You should be careful about backing up, as always.

It's a shame such a great tool has such a lame bug.

Note: Data Dude is the nickname for the Microsoft project formally known as Visual Studio Team System 2008 Database Edition.

Wednesday, July 30, 2008

Adding a File to a Setup Project in Visual Studio

I've had serious installer trouble after adding a C# project's content file to a Visual Studio Setup project. Try as I might, each time I tried to use a content-file output from another project I got a failed install. Repeated attempts to install gave me an erroneous error saying the service was already installed. This was because the failed install left an orphaned registry entry. Wonderful. I had to use "sc delete" to get rid the registry entry.

Lesson learned: just right click on the installer and select "add file." I referenced a file in the other project in this manner and the installer project created a relative reference. Should do the trick.

The reason for adding a content file to the install was to allow a perl script to be executed by the application.

SharePoint UI Madness

For most user-level activities, SharePoint's UI has typically been adequate. The administrative features, however, continue to sport UI problems that are world class. Someday I'll get around to making a list of my absolute most hated UI blunders in SharePoint. I think it would be best to wait for a day when I'm already in a bad mood because some of these problems seriously perturb me.

Today I had to deal with one that really got me going: adding and editing user accounts for a SharePoint site. You would think that the link to that functionality would just jump out at you once you navigate to site admin (called "settings" in SharePoint-speak) . Nope. The appropriate link appears exclusively in the left sidebar of the "people" page for your site. First navigate to the settings page of your site by using the "Site Actions" dropdown in the upper right hand corner of the page. Then click on "People and Group" link under the "User and Permissions" list. On the ensuing page, People.aspx, look to the left nav for the bolded words "All People." Once you click this link, you'll see all the "people." Thus, in getting to this page, to do something really basic, we've gone through three different navigation schemes!

Below is a screen shot showing the "All People" link.

Wednesday, August 15, 2007

Parsing Command Line Parameters in VC++

One of the most confounding things in the C/C++ programming world is the unnaturalness of C-style "strings." I put quotation marks around "strings," because when you're C-stylin', your dealing actually with arrays of chars, not string-like objects. Chances are if you're coding in C++ what you really want are STL strings, not arrays of chars. This confusing situation is a much bigger problem for novices than old hands, but in either case it's still a bit awkward. Unless you're also using .NET (CLI), arrays of chars are unavoidable when parsing command line parameters--a feature that most sophisticated applications require.

If you're using VC++ (versions VC++2003, VC++2005, or VC++2008) as your IDE, your "main" function, which is actually "t_main" in VC++, confronts you not with char* but _TCHAR*, making things even more cryptic. (The "t" and "T" characters refer to the configurability of VC++2008 to handle unicode or not, depending whether the _UNICODE is defined at compilation. But you knew that.) I'm really puzzled about not yet seeing a book author take on this common chore. You could have a pretty annoying Google-session trying get sample code to parse command line parameters with this version of the main function.

Most Google group queries I found on this topic tend to focus on conversion functions. Though I almost always love a clever, succinct function to do my dirty work, in this case I may pass, because it only takes a few lines of memorable code to slip the chars into a handy vector of strings. In this case, we use wstring (for "wide string") instead of string. The do-while below adds a de-referenced pointer to wchar_t (the "wide" version of char)

wstring a_wstring;
do a_wstring += *argv[i];
while(*argv[i]++);

The key thing to realize is that wstring knows what do with char's.

Here's a short program that stores the parameters in a vector and also displays them to the

#include "stdafx.h"
#include
#include
#include
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
vector args;
for(int i =0;i<argc;i++)
{
wstring a_wstring;
do a_wstring += *argv[i];
while(*argv[i]++);
args.push_back(a_wstring);
cout << i<<"\n";
wcout << args[i] << "\n";
}
return 0;
}

You should be able to do just about whatever you want with the parameters after putting them into a vector of wstrings.