Serge's Technology View

Talk about Technologies, Software Architecture and Management

Archive for January, 2009

Assert is your friend… not an end-user’s

As a long time Delphi and C# programmer one become used to some features of the language and may not go deep into “philosophical” thinking about such features. This often happen with Asserts

What is Assert or Assertion?

By its definition Assert:

  • state categorically
  • affirm: to declare or affirm solemnly and formally as true
  • insist: assert to be true
  • In Computing (wiki): “an assert is a predicate (i.e., a true–false statement) placed in a program to indicate that the developer thinks that the predicate is always true at that place”

In general, using assert in the code proven to be useful in many situations because it “checks for a condition and outputs the call stack if the condition is false” and it could help to debug some strange situations in the code.

Assert is your friend

This method is for programmers to use. But what happen often when something is convenient, it started to be used excessively. Why it is happening?

Let’s look at the declaration of Assert in C# (3.x). There are two versions of the Assert(): Debug.Assert() and Trace.Assert(), both in System.Diagnostics namespace.

// Checks for a condition and outputs the call stack
// if the condition is false

[ConditionalAttribute("TRACE")]
public static void Assert(bool condition)

[ConditionalAttribute("TRACE")]
public static void Assert(bool condition, string message)

[ConditionalAttribute("DEBUG")]
public static void Assert(bool condition)

[ConditionalAttribute("DEBUG")]
public static void Assert(bool condition, string message)

As we can see from above code, Assert is to be used for Testing and Debugging and therefore should not be used as a way to present any information to the end-user.

Helping yourself

As useful as it seems, even then Assert infrastructure may not be used to full extend. In the sample declarations above we can see that logic can be invoked with and without providing any additional information.
Imagine how useful is a message “Project raised an Assert in line X” compare to “Project raised an Assert with the Message in line X”.
First option gives you idea where something failed, where second actually tells you what went wrongand where. Let’s use power of the tool-set and provide ourselves with useful information.

Assert is NOT for an end-user

I was asked recently (this seems to be a ongoing discussion) – “Why a programmer should not be using asserts as a regular approach in code conditions validation even when it comes to a production code?”

By default, Assert would show a message box with some information and the current Call Stack. This information, while being helpful to the developer, would not tell much to the user.

With custom TraceListener introduced, message can be hidden from the user and information could be stored, but it is not how it should be used by definition.

If information is expected to be presented to the user in any form, it could be achieved in a form not an exceptional, intended for debugging, situation, but by using regular methods: message box, application log, Windows event log, etc.
Even in the case of component development it is desired to use exceptions (raise/throw) to “bubble” proper message to the error handling layer.

The throw statement is used to signal the occurrence of an anomalous situation (exception) during the program execution.

Assert is a conditional logic

Last, final and probably major concern here is that in Release environment Debug and even Trace functionality would be disabled and therefore, any code/logic which depend on Assert() would be suppressed and all the nice validations became worthless (see declaration above)… and Access Violation errors starting pop up unexpectedly.

SQL Server 2008: moving forward

SQL Server 2008 has been available since Aug 6, 2008. This does not include CTP (Feb 2008) time-frame.
We are close to the year milestone now.

To my surprise there are still questions around if moving to a new version is necessary.

This is especially difficult question to discuss/suggest when SQL Server 2005 adoption cycle is just about being complete.

  • We all know about “have to wait until first SP is out” rule.
  • What is good about it to justify spending another chunk of IT budget?

To answer first question, there is a cumulative update 1 available since Nov, 2008. One could count it as SP1.

To answer second question could be more difficult.

There is Product Overview White Paper available along with Data sheet where main differences between 2005 and 2008 versions are highlighted.

As you could see many features are enterprise level, but many are to make life regular developers easier as well.

To summarise, while SQL Server 2008 could be considered just an extension to 2005, major enhancements are:

  1. Transparent Data Encryption – add protection to your data storage without custom and usually process extensive solutions
  2. External Key Management – integrate 3rd party security keys and hardware
  3. Enhanced Auditing – monitor data access and modification
  4. Advanced Database Mirroring – data corruption protection, improved performance, new performance counters
  5. Hot CPU management – change hardware configurations without downtime (for supported hardware platforms)
  6. Performance improvements, Service Broker Scalability, Integrated Full-Text Search, Sparse Columns (“zero storage”), no 8,000 byte limit - manage allocated resources and priorities, query plans optimizations, data compression, backup compression (finally :) ), extended performance monitoring tools, 64 bit platform optimization (RAM, hardware, etc)
  7. SQL Server Integration Services (SSIS) improvements
  8. Policy-Based Management
  9. Installation improvements
  10. ADO.Net Entity Framework and CLR Integration – Object-Oriented style support instead of Table/Field approach
  11. LINQ – even though some pieces (?temporary solutions?) were available before, now LINQ becomes first-class citizen for SQL Server. Forget your T-SQL and program using LINQ syntax.
  12. T-SQL improvements – even though LINQ may be a way to go, T-SQL still is not forgotten with added support for Table Value Parameters (TVP), Object Dependencies Views and Functions, new data types: DATE, TIME, DATETIMEOFFSET, DATETIME2 allowing conserve storage space and improve time precision, FILESTREAM, GEOGRAPHY and GEOMETRY  datatypes, and HIERARCHYID for better support of tree based data structures
    Compound operators – lovely “+=” syntax and in-line variable assignment DECLARE @myVar int = 5
    MERGE support – manage data inserts/updates in one SQL statement
  13. SQL Management Studio gets IntelliSense and other improvements and better Source Control integration
  14. SQL Management Studio T-SQL debugging – not as robust as it is in Visual Studio, but sufficient in many situations.
  15. Table Partitioning management
  16. Hot-swap data connectors – easier support for disconnected data applications
  17. Improved MS Reporting Services and report builder- MS Word/Excel/SharePoint integration improved
  18. OLAP support improvements

Even if you decided to stay with 2000/2005 version, keep in mind a few things which will make your future upgrades easier.

The list of features dropped/changed in SQL Server 2008.

  1. Deprecated SQL Server Features in SQL Server 2008
    • DTS support (link) is replaced with SSIS (migration)
    • ADHelper service
    • SOAP/HTTP endpoints, sys.http_endpoints, sys.endpoint_webmethods (Transact-SQL)
  2. Discontinued SQL Server Features in SQL Server 2008
    • Some SMO Classes has been discontinued
    • Surface Area Configuration Tool (SAC)
    • Discontinued Command Prompt Parameters for SQL Server Setup
  3. SQL Server Native Client has been upgraded with some behavior changes

How about some technical data and stats? To begin with, Microsoft team is no longer publicly presents any data which will show some benchmarks between versions, editions or between different database server platforms, so we have to relay on someone outside do the job.

Yes, comming with mathematical background I can agree with some arguments that this data is not accurate and always represent just what was tested in each particular case in each particular hardware configuration. With statistics being used by marketing department it can be very interesting.

Therefore, we have to be very sceptical about any stats presented anywhere. Nevertheless:

As far as my own experience with a new version - it has been positive and I would highly recommend to go with this upgrade.

Visual Studio 2008 and IIS 7

Deploying ASP.Net applications is always fun when it comes to packages which are more complex then usual and require additional actions taken and this one is not an exception.

I think this topic run into the ground, but it seems to come back again and again. I guess the reason for that is “default” state set for the environment…

After upgrade of operating system to Vista IIS 7 would be installed. This brings some “inconveniences” into usual development process. Aside from worrying about disabling UAC, few other things usually breaks.

One of them is that setup package for ASP.Net application created in Visual Studio starts to fail with the error that installer session closed improperly and process has to be restarted (or similar).

If we look into installer log (check here on how to enable debug mode) the following error could be found:

Action 11:18:53: WEBCA_SetTARGETSITE.
Action start 11:18:53: WEBCA_SetTARGETSITE.
MSI (c) (B4:A4) [11:18:53:657]: Note: 1: 2235 2: 3: ExtendedType 4: SELECT `Action`,`Type`,`Source`,`Target`, NULL, `ExtendedType` FROM `CustomAction` WHERE `Action` = ‘WEBCA_SetTARGETSITE’
MSI (c) (B4:A4) [11:18:53:661]: Creating MSIHANDLE (1) of type 790542 for thread 4260
MSI (c) (B4:4C) [11:18:53:662]: Invoking remote custom action. DLL: C:\Users\SDOSYU~1\AppData\Local\Temp\MSI2978.tmp, Entrypoint: SetTARGETSITE
MSI (c) (B4:F0) [11:18:53:666]: Cloaking enabled.
MSI (c) (B4:F0) [11:18:53:666]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (B4!14) [11:18:53:726]: Creating MSIHANDLE (2) of type 790531 for thread 4116
INFO   : [01/02/2009 11:18:53:726] [SetTARGETSITE ]: Custom Action is starting…
INFO   : [01/02/2009 11:18:53:727] [SetTARGETSITE ]: CoInitializeEx – COM initialization Apartment Threaded…
ERROR  : [01/02/2009 11:18:53:729] [SetTARGETSITE ]: FAILED: -2147221164
ERROR  : [01/02/2009 11:18:53:730] [SetTARGETSITE ]: Custom Action failed with code: ’340′
INFO   : [01/02/2009 11:18:53:731] [SetTARGETSITE  ]: Custom Action completed with return code: ’340′

Very informational… Who would guess that it simply comes to support for IIS 6 API. In IIS 7 it called “IIS 6 Management compatability”.

Usually this module is not installed by default and we have to actually enable it.
Very simple and very quick solution is to go “Control Panel\Programs and Features\Turn Windows features on or off” and then click the check box.

iis7support

There is one more problem which may be encountered on 64 bit machine – support for 32 bit assemblies is disabled by default. To reenable, change Application Pool Defaults for your IIS 7 installation:
32bitaspon64bitos

Valid XHTML 1.0 Transitional  Valid CSS!