Second Stanza

April 30, 2008

VC 6 to VS 2008

Filed under: C and C++ — Tags: , — dfbaskin @ 9:42 am

I was porting a project from Visual Studio 6 so that it would compile under Visual Studio 2005. It was a mixed C/C++ MFC-based project. Of course, the C/C++ compiler has gotten stronger and some older syntax is no longer accepted by default. I found the following definitions helpful in getting the source code compiled:

  • _CRT_SECURE_NO_WARNINGS – This allows me to disable the warnings about not using the new safe functions, instead of the normal unsafe ones, like strcpy. I know, bad idea, but we were just trying to get some legacy code running.
  • _CRT_NONSTDC_NO_WARNINGS – This allows me to disable the warnings about POSIX functions, such as filelength and chdir.
  • _USE_32BIT_TIME_T – time_t is now a 64-bit value, by default. This define allows me to use the old 32-bit value.

One other thing I had to address was the use of the COccManager class. For VC6, this class was not public but it was included in the MFC source code. This knowledgebase article details how to use this class. This technique worked well and gave me the control within the CHtmlView class that I needed to manipulate the functionality of the MSHTML control.

In VS2008, however, this class was made public and the CHtmlView instantiated its own instance of a COccManager class. Now you have to override the CreateControlSite() method in order to make use of your custom COccManager class. Once I made the switch, the CHtmlView object using my custom COccManager worked as I expected.

April 28, 2008

Time Slot Reservations using SharePoint

Filed under: SharePoint — Tags: — dfbaskin @ 9:21 pm

I needed to set up a finite list of time slots where my SharePoint users can reserve at most one slot. (Specifcally, it’s a list of final exam time slots, one reservation per student.) I played around with the Room and Equipment Reservations templates, but they didn’t support this concept.

So after researching different options, it seemed to me that this could be implemented using a custom list that contains the following fields:

  • Description – The description of the time slot (I just used the ‘Title’ field).
  • Date and Time – The date and time of the start of the time slot.
  • Reserved By – The user that has reserved the time slot, which only contains a value when the time slot is actually reserved.

Reservations, then, must follow these rules:

  1. Only members of a single, specific SharePoint group may actually make reservations.
  2. The users making reservations may not otherwise edit the list (but the owner of the list may).
  3. A single user may only reserve one time slot.
  4. A user may not reserve a time slot for a different user.

The list definition contains the elements I need but there is extra work required to enforce these rules.

Item #1 is covered by the “Person or Group” SharePoint data type. The “Reserved By” field is set up to only allow the selection of a user from a specific SharePoint group.

Item #2 is covered by making the list read-only for the users making the reservations.

For Item #3, code must be added so that any other reservation made by a user must be removed before adding a new reservation.

For Item #4, the reservations editor should select the current user when making a resevation.

There are a number of ways to implement all of this, but I chose to create a web part. I was interested in displaying the time slots in a calendar view, with a “Reserve” link to make it as simple as possible for a user to reserve the slot. Therefore, the web part makes use of the SPCalendarView control, populating it with SPCalendarItem objects that are based on the items from the list discussed above. The link to the calendar item is customized to allow the web part to make the reservation when the link is clicked. Then, the list item page is displayed to show the new reservation (or even if no reservation was made due to the fact the time slot is already reserved or the user is not in the correct SharePoint group).

See the links below to view or download the source code.

There are many things that could be done to this source to make it more fully functional. For example:

  1. There is not a lot of feedback given to the user if a reservation is made or not. If a reservation cannot be made, the user should at least know why.
  2. The calendar view should be handled better so that it can actually switch between month, week, and day views.
  3. It would be nice for the calendar to automatically display the month that contains the first time slot, not just the current month. The work around I use is to add “?CalendarDate={month}%2F{day}%2F{year}” to the query string when adding a link to the reservation’s web part page.
  4. A user should be able to remove a reservation. Right now, a user with edit rights to the list must perform this function.
  5. The web part needs editable properties that can be used to define the name of the list, field names, and the SharePoint group name. Currently, these names are hard-coded into the web part.
  6. A user shouldn’t be able to reserve a time slot in the past.

Download / View Source Code
(View requires Microsoft Silverlight 1.0 and Internet Explorer)

April 10, 2008

Resetting Collation in SQL Server 2005

Filed under: SQL Server — Tags: — dfbaskin @ 7:02 am

I accidentally installed a development version of SQL Server 2005 with a case-sensitive collation. This upset other SQL databases I was working with that were not expecting table names and etc. to be case sensitive. In SQL Server 2005, you can reset the collation by using setup with the REBUILDDATABASE parameter.

Details about this process are here.  Details about setting the collation are here.

The following command (one line) worked for me:

start /wait setup.exe /qb INSTANCENAME=MSSQLSERVER
     REINSTALL=SQL_Engine
     REBUILDDATABASE=1
     SAPWD=password
     SQLACCOUNT=doman\user SQLPASSWORD=password
     SQLBROWSERACCOUNT=doman\user SQLBROWSERPASSWORD=password
     SQLAGTACCOUNT=doman\user SQLAGTPASSWORD=password
     SQLCOLLATION=Latin1_General_CI_AS_KS_WS
     ASCOLLATION=Latin1_General_CI_AS_KS_WS

(I originally tried this from the “\Program Files\Microsoft SQL Server\90\Setup Bootstrap” directory, but this generated an error saying an .MSI file was not found. But it worked fine from the original installation media.)

However, there was a problem trying to reapply SP2 (found here). There have been additional updates since SP2 was released (described in detail here), which Windows Update had already applied. Therefore, I could not apply the SP2 updates since components were already at a later version.

From here, I assume you have two options:

  1. Uninstall SQL Server altogether, reinstall, and apply the service pack. This, of course, defeats the purpose of using the REBUILDDATABASE option in the first place.
  2. Request the cumulative service pack update (described here) and apply it.

I ended up going with the first option.

Create a free website or blog at WordPress.com.