SQL Server 2008 and PowerShell

SQL Server 2008 now has support for PowerShell.

SQL Server provides two PowerShell snap-ins that implement:

  • A SQL Server provider, which enables a simple navigation mechanism similar to file system paths. You can build paths similar to file system paths, where the drive is associated with a SQL Server management object model, and the nodes are based on the object model classes. You can then use familiar commands such as cd and dir to navigate the paths similar to the way you navigate folders in a command prompt window. You can use other commands, such as ren or del, to perform actions on the nodes in the path.
  • A set of cmdlets, which are commands used in PowerShell scripts to specify a SQL Server action. The SQL Server cmdlets support actions such as running a sqlcmd script containing Transact-SQL or XQuery statements.

Resources:
SQL Server PowerShell Overview

Pre-written Powershell scripts for SQL Server Management

SQL Server Standard Edition 2005 upgrade to SQL Server Standard 2008 upgrade rules fail

I had an issue with SQL Server 2008 Upgrade Rules. I was running SQL Server 2005 Standard. I could not get past the Upgrade Rules. I told me I was trying to upgrade to an incompatible version and to see the version matrix. It made no sense to me. I ran “Select @@version” and it all came back correct. I did some digging into the Microsoft SQL Server100Setup BootstrapLogSummary.txt. I found out that my Reporting Services and tools version were installed with SQL Server 2005 Developer Edition.

What! How could that be? Yes, that is what I had installed, so not matter what version I tried to upgrade to it failed. The installer could not figure out what to do.

The Solution:
None really, I could not upgrade.
So, I had to re-create my environment with a new clean install of SQL Server 2005 Standard w/ Reporting Services then go through my upgrade tests. All was fine after that.

Upgrade to SQL Server 2008 fixes Reporting Services nested data region export to Excel

I recently upgraded to SQL Server 2008. The primary reason was to fix an issue with SQL Server Reporting Services – Excel Export issues with nested data regions.

“Any data region nested inside of a table or matrix data region is not supported. An error is displayed in Excel if this layout is encountered.”

They reportedly fixed this issue in SQL Server 2008. I my testing supports the claim and we no longer have the “nested data region errors”.

I must say that I was impressed with the new installer. Microsoft goes to great lengths to validate your SQL Server configuration before trying to upgrade. I had one upgrade issue that I talk about in this post, that was caused by me.

Validate .NET control and javascript confim before postback

< asp:imagebutton id=“ibDelete” causesvalidation=“true” onclientclick=“return checkDelete()” validationgroup=“ModalValidation” alternatetext=“Delete Journal” runat=“server” imageurl=“~/images/icons/delete.gif” onclick=“ibDelete_Click”/>

function checkDelete(){
if(Page_ClientValidate())
{
var record=confirm(‘Are you sure you want to delete this record?’);
if(record == 1)
{
return true;
}
else if(record == 0)
{
return false;
}
}
}

Manually calling ASP.NET Validation with JavaScript

I put a version of this function on the OnClientClick event of a ASP.NET button control.

The requirement I had was to find out how many validation controls fired, show a modal dialog and then set focus to the first Invliad Validator control. I left the modal dialog code out of this example as there are plenty of good resources on the web.

Page_ClientValidate() will force validation on the client side.

Page_Validators is a collection of Validation controls on the page in which you can access and evaluate however you see fit.

The ValidatorFocus() function is for my solution is called when my modal closes.

function ValidationCatcher()
{
//force .net validation
Page_ClientValidate();

var count = 0;
for(i=0; i < Page_Validators.length; i++){
if(!Page_Validators[i].isvalid)
{
count = count+1;
}
}
//set msg for dialog message
alert(count);

}

function ValidatorFocus()
{
var i;
for (i = 0; i < Page_Validators.length; i++) {
if (!Page_Validators[i].isvalid) {
document.getElementById(
Page_Validators[i].controltovalidate).focus();
break;
}
}
}

A few resources that I came across:
http://timstall.dotnetdevelopersjournal.com/validation_tips_for_validators.htm

http://www.codeproject.com/KB/validation/customvalidationscripts.aspx

Logging in .NET

Options:
Enterprise Library 3.1

  • Populating and raising events from code
  • Populating a log message with additional context information
  • Tracing activities and propagating context information
  • Checking filter status before constructing log messages.
  • Configuring options for trace listeners
  • Directing different event types to different trace listeners
  • Configuring log filters
  • Configure logging to be performed from a central location
  • Creating a custom trace listener

log4net 1.2.10
log4net is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4net it is possible to enable logging at runtime without modifying the application binary. The log4net package is designed so that log statements can remain in shipped code without incurring a high performance cost. It follows that the speed of logging (or rather not logging) is crucial.

At the same time, log output can be so voluminous that it quickly becomes overwhelming. One of the distinctive features of log4net is the notion of hierarchical loggers. Using these loggers it is possible to selectively control which log statements are output at arbitrary granularity.

log4net is designed with two distinct goals in mind: speed and flexibility

Web page debuggers I can’t live without!

Firebug for Firefox:

You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

Internet Developer Toolbar for IE:

  • Explore and modify the document object model (DOM) of a Web page.
  • Locate and select specific elements on a Web page through a variety of techniques.
  • Selectively disable Internet Explorer settings.
  • View HTML object class names, ID’s, and details such as link paths, tab index values, and access keys.
  • Outline tables, table cells, images, or selected tags.
  • Validate HTML, CSS, WAI, and RSS web feed links.
  • Display image dimensions, file sizes, path information, and alternate (ALT) text.
  • Immediately resize the browser window to a new resolution.
  • Selectively clear the browser cache and saved cookies. Choose from all objects or those associated with a given domain.
  • Display a fully featured design ruler to help accurately align and measure objects on your pages.
  • Find the style rules used to set specific style values on an element.
  • View the formatted and syntax colored source of HTML and CSS.

Sys.WebForms.PageRequestManagerServerErrorException: 500

Sys.WebForms.PageRequestManagerServerErrorException:An unknown error occured while processing the request on the server.The status code returned from the server was:500

The real error was:
Invalid postback or callback argument. Event validation is enabled using;<pages enableeventvalidation=”true”/>; in configuration or <@ Page EnableEventValidation="true" %/>; in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

The fix for me:
EnableEventValidation=”false”