Skip to main content

Posts

Showing posts from July, 2014

T-SQL: Easy way to check for existence of a temp table

Normally I'd do something like selecting from sysobjects to find if a temp table exists, but I found this little gem to drop a global temp table at the start of a query (in case it wasn't cleaned up in the previous execution):

IF(object_id('tempdb..##tmpTable') IS NOT NULL)
DROP TABLE ##tmpTable
GO

I'm sure you can come up with a better way to do this rather than using a global temp table, but a local one wasn't going to work in this context since I was using a combination of EXEC and OpenQuery to select from Active Directory, and regular local temp tables seem to disappear upon leaving EXEC, perhaps due to the connection changing or something?

IIS and ASP.NET 404 error handlers don't play nicely together

While trying to setup both ASP.NET as well as IIS error-handling, I noticed that IIS wasn't dealing with certain 404 errors in which the file extension was wrong.  For example, I could request ThisFileDoesntExist.aspx and that would redirect to NotFound.aspx just fine, but WrongExtension.aspz would kick the user out to the ugly default IIS 404 error page.

So I did a bit of investigation and found this post, which pointed out that, in your web.config, if you have both this (relevant parts highlighted):

<customErrors defaultRedirect="~/Error.aspx" mode="On" redirectMode="ResponseRedirect">
    <error statusCode="404" redirect="~/NotFound.aspx" />
</customErrors>

As well as this:

<httpErrors errorMode="Custom" existingResponse="Replace">
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" pat…