Monday, June 16, 2008

Calculating Work Days

I ran across the following T-SQL function to calculate the number of workdays between a given start date and end date. (This does not exclude non-weekend non-workdays such as holidays.)

Thanks to Jeff Moden for this function, which I found at http://www.sqlservercentral.com/articles/Advanced+Querying/calculatingworkdays/1660/:

SELECT
(DATEDIFF(dd, @StartDate, @EndDate) + 1)
-(DATEDIFF(wk, @StartDate, @EndDate) * 2)
-(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)

Thursday, June 12, 2008

ASP.NET Menu control & "downlevel" browsers

I ran into this fix when trying to get an ASP.NET 2.0 Menu control to render correctly on Safari. It turns out that ASP.NET thinks Safari is a downlevel browser (meaning incapable of rendering XHTML), so it sends a funky (and generally non-functioning) rendering of the Menu control down to the browser.

This isn't guaranteed to work in all cases, but in my case, adding the following Page directive did the trick:

<%@ Page ClientTarget="uplevel"... %>

Wednesday, June 11, 2008

Result set was not generated by a SELECT statement

This obscure error occurred when using PHP ODBC to retrieve values from a stored procedure. It turns out this occurs when the stored procedure SELECTs data from one or more TEXT columns. Convert these columns to VARCHAR(8000) and you're good to go.

Monday, June 9, 2008

AGONY: Vista Business x64 and SQL Server Management Studio

I have been fighting this one for days: my computer is currently joined to our corporate domain, but I am logged in as a local user. I've used "Manage network passwords" to add all of the relevant credentials for domain access. However, I still get the following error when logging in via Windows Authentication in SSMS:

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

The error logs show that the SSPI handshake is failing - meaning that Windows is not passing along my valid domain credentials to SQL Server.

Finally, I found a workaround that deals with what I'm experiencing by making use of the runas command. It's hacky, and this is definitely due to Vista's "wonderful feature", but it gets the job done. Thanks to Jason Follas for the following tip:

http://www.jasonfollas.com/wiki/Default.aspx?Page=SQL%20Management%20Studio%20on%20Vista&AspxAutoDetectCookieSupport=1

For the record, we should not have to do this.

Wednesday, April 23, 2008

How to install Windows SharePoint Services 3.0 Tools to XP or Vista

Another blog ripoff, this time from Janne Mattila, on how to trick XP or Vista machines into thinking that WSS 3.0 is installed so that you can install WSS 3.0 Tools for Visual Studio 2005:

http://blogs.msdn.com/jannemattila/archive/2007/08/16/how-to-install-windows-sharepoint-services-3-0-tools-to-xp-or-vista.aspx

Details: it's a registry hack...

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0]
"Sharepoint"="Installed"

Tuesday, April 22, 2008

How to Create a MOSS 2007 VPC Image

Wonderful series of posts by Tony Zink outlining exactly what you need to do to set up Microsoft Office SharePoint Server 2007 on a Virtual PC with a SQL Server 2005 backend and full e-mail capabilities:

http://www.pptspaces.com/sharepointreporterblog/Lists/Posts/Post.aspx?ID=28

Thursday, April 3, 2008

LINQ to SQL and the DataGridView control

A DataGridView control won't bind directly to an IEnumerable object, so two options are:

1. Create a BindingSource, set its DataSource to the IEnumerable object, then set the DataGridView.DataSource property to the BindingSource.

2. Bind the DataGridView.DataSource property to the IEnumerable object's ToList() method.

Thanks to Ken Tucker on Microsoft Forums for this tip.