Wednesday, 9 September 2009

Roadtrip and Deep Fried Bytes

I just offered to do a family favor which means I will be taking a roadtrip up to the north of Scotland via my parents next week.  I have to admit I’m really looking forward to the drive and a small break from the book :)

I’m gonna load up my iPhone with the backlog of Deep Fried Bytes episodes 

If you haven’t checked it out, it really is an awesome podcast show.  I’ve listened to the first 4 episodes so far and they are just great.  The shows are particularly cool for me as I hung out with one of the hosts (Keith Elder) and many of the guests at Nashville.  I’m especially looking forward to listening to the Devlink podcast, which is just out.

So far I’ve listened to the interview war stories (awesome), twitter podcast (very good), digg interview (really cool, nice to hear a non .net perspective), and the developing .net on a mac episode (again awesome episode).  I’m incredibly impressed with the diversity off the podcast and really looking forward to listening to more on the trip.

This show is just as good as DNR or Hanselminutes but has a bit of a different flavor (a deep fried one even), if you haven’t checked it out yet, do it now.  Listening to the show on the way to Scotland is obviously appropriate with it being the land of the Deep Fried Mars bar, Pizza and well anything really.

Obviously looking forward to spending a little time with my family, I don’t think I’ve been back across the border in a while now.  So will be nice to see how much my accent digresses back to it’s Scottish roots :)

Monday, 31 August 2009

Silverlight: Offline talk at Devlink

I just want to say a big thanks to everyone who came to my session at Devlink.  I had an absolutely fantastic time and I really enjoyed presenting this session to you guys.

I really felt that this session was more than just a presentation but also a conversation and I thank you for participating in it with me.

I really hope to return to Devlink next year (and other U.S. Conferences) so I hope to see you again.  I will post up my Devlink experiences later on this week hopefully.

Again, a big thank you for coming to my talk and the slides and demo code are available from here.

Sunday, 30 August 2009

SQL Azure Database Session Database

Ok, so here is the good news and the bad news.

The good news is that I created my SQL Azure Session Database Script (from hacking InstallPersistSQLState.SQL) you can’t use InstallSQLState.sql as it uses tempdb.

The bad news is that to make it work you need to create a custom session provider (no easy task).  You need a custom provider as the SQL Session Provider needs to use the @@ parameter in the GetMajorVersion Stored Procedure which SQL Azure database doesn’t support.  I also haven’t tested this script, so use at your own risk

I am realizing I don’t have time to write the provider at the moment as I am still in the middle of writing my “Azure in Action” book (along with Brian Prince), so here is the script for the database.

All you need to do is Create a Database in SQL Azure called ASPState and run this script.

/*********************************************************************
  InstallPersistSqlState.SQL                                               
  Installs the tables, and stored procedures necessary for          
  supporting ASP.NET session state.                                 

  Copyright Microsoft, Inc.
  All Rights Reserved.
  Modified by chrishayuk to work in SQL Azure Database
  P.S. You will need a worker role or console session to clean up expired sessions

*********************************************************************/

--SET QUOTED_IDENTIFIER OFF
--GO
--SET ANSI_NULLS ON
--GO

PRINT ''
PRINT '------------------------------------------------'
PRINT 'Starting execution of InstallPersistSqlState.SQL'
PRINT '------------------------------------------------'
PRINT ''
PRINT '--------------------------------------------------'
PRINT 'Note:                                             '
PRINT 'This file is included for backward compatibility  '
PRINT 'only.  You should use aspnet_regsql.exe to install'
PRINT 'and uninstall SQL session state.                  '
PRINT ''
PRINT 'Run ''aspnet_regsql.exe -?'' for details.         '
PRINT '--------------------------------------------------'
GO

/*****************************************************************************/

-- chrishayuk -- Commented out the creation of the database
--/* Create and populate the session state database */
--IF DB_ID(N'ASPState') IS NULL BEGIN
--    DECLARE @cmd nvarchar(500)
--    SET @cmd = N'CREATE DATABASE [ASPState]'
--    EXEC(@cmd)
--END   
--GO

/* Drop all tables, startup procedures, stored procedures and types. */

/* Drop the DeleteExpiredSessions_Job */

-- chrishayuk -- Commented out the dropping of the DeleteExpiredSessions Job
--DECLARE @jobname nvarchar(200)
--SET @jobname = N'ASPState' + '_Job_DeleteExpiredSessions'
-- Delete the [local] job
-- We expected to get an error if the job doesn't exist.
--PRINT 'If the job does not exist, an error from msdb.dbo.sp_delete_job is expected.'
--EXECUTE msdb.dbo.sp_delete_job @job_name = @jobname
--GO

DECLARE @sstype nvarchar(128)
SET @sstype = N'sstype_persisted'

IF UPPER(@sstype) = 'SSTYPE_TEMP' AND OBJECT_ID(N'dbo.ASPState_Startup', 'P') IS NOT NULL BEGIN
    DROP PROCEDURE dbo.ASPState_Startup
END   

IF OBJECT_ID(N'dbo.ASPStateTempSessions','U') IS NOT NULL BEGIN
    DROP TABLE dbo.ASPStateTempSessions
END

IF OBJECT_ID(N'dbo.ASPStateTempApplications','U') IS NOT NULL BEGIN
    DROP TABLE dbo.ASPStateTempApplications
END

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'GetMajorVersion') AND (type = 'P')))
    DROP PROCEDURE [dbo].GetMajorVersion
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'CreateTempTables') AND (type = 'P')))
    DROP PROCEDURE [dbo].CreateTempTables
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetVersion') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetVersion
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'GetHashCode') AND (type = 'P')))
    DROP PROCEDURE [dbo].GetHashCode
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetAppID') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetAppID
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetStateItem') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetStateItem
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetStateItem2') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetStateItem2
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetStateItem3') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetStateItem3
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetStateItemExclusive') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetStateItemExclusive
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetStateItemExclusive2') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetStateItemExclusive2
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempGetStateItemExclusive3') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempGetStateItemExclusive3
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempReleaseStateItemExclusive') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempReleaseStateItemExclusive
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempInsertUninitializedItem') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempInsertUninitializedItem
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempInsertStateItemShort') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempInsertStateItemShort
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempInsertStateItemLong') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempInsertStateItemLong
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempUpdateStateItemShort') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempUpdateStateItemShort
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempUpdateStateItemShortNullLong') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempUpdateStateItemShortNullLong
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempUpdateStateItemLong') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempUpdateStateItemLong
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempUpdateStateItemLongNullShort') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempUpdateStateItemLongNullShort
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempRemoveStateItem') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempRemoveStateItem
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'TempResetTimeout') AND (type = 'P')))
    DROP PROCEDURE [dbo].TempResetTimeout
GO

IF (EXISTS (SELECT name FROM sys.objects WHERE (name = N'DeleteExpiredSessions') AND (type = 'P')))
    DROP PROCEDURE [dbo].DeleteExpiredSessions
GO

CREATE PROCEDURE dbo.TempGetVersion
    @ver      char(10) OUTPUT
AS
    SELECT @ver = '2'
    RETURN 0
GO

CREATE PROCEDURE dbo.GetMajorVersion
    @ver int OUTPUT
AS
BEGIN
    SET @ver = 10
END
GO

CREATE PROCEDURE dbo.CreateTempTables
AS
    CREATE TABLE [ASPState].dbo.ASPStateTempSessions (
        SessionId           nvarchar(88)    NOT NULL PRIMARY KEY,
        Created             datetime        NOT NULL DEFAULT GETUTCDATE(),
        Expires             datetime        NOT NULL,
        LockDate            datetime        NOT NULL,
        LockDateLocal       datetime        NOT NULL,
        LockCookie          int             NOT NULL,
        Timeout             int             NOT NULL,
        Locked              bit             NOT NULL,
        SessionItemShort    varbinary(7000) NULL,
        SessionItemLong     varbinary(max)  NULL,
        Flags               int             NOT NULL DEFAULT 0,
    )

    CREATE NONCLUSTERED INDEX Index_Expires ON [ASPState].dbo.ASPStateTempSessions(Expires)

    CREATE TABLE [ASPState].dbo.ASPStateTempApplications (
        AppId               int             NOT NULL PRIMARY KEY,
        AppName             char(280)       NOT NULL,
    )

    CREATE NONCLUSTERED INDEX Index_AppName ON [ASPState].dbo.ASPStateTempApplications(AppName)

    RETURN 0
GO  

/*****************************************************************************/

CREATE PROCEDURE dbo.GetHashCode
    @input varchar(280),
    @hash int OUTPUT
AS
    /*
       This sproc is based on this C# hash function:

        int GetHashCode(string s)
        {
            int     hash = 5381;
            int     len = s.Length;

            for (int i = 0; i < len; i++) {
                int     c = Convert.ToInt32(s[i]);
                hash = ((hash << 5) + hash) ^ c;
            }

            return hash;
        }

        However, SQL 7 doesn't provide a 32-bit integer
        type that allows rollover of bits, we have to
        divide our 32bit integer into the upper and lower
        16 bits to do our calculation.
    */
    DECLARE @hi_16bit   int
    DECLARE @lo_16bit   int
    DECLARE @hi_t       int
    DECLARE @lo_t       int
    DECLARE @len        int
    DECLARE @i          int
    DECLARE @c          int
    DECLARE @carry      int

    SET @hi_16bit = 0
    SET @lo_16bit = 5381
    SET @len = DATALENGTH(@input)
    SET @i = 1
    WHILE (@i <= @len)
    BEGIN
        SET @c = ASCII(SUBSTRING(@input, @i, 1))

        /* Formula:                       
           hash = ((hash << 5) + hash) ^ c */

        /* hash << 5 */
        SET @hi_t = @hi_16bit * 32 /* high 16bits << 5 */
        SET @hi_t = @hi_t & 0xFFFF /* zero out overflow */
        SET @lo_t = @lo_16bit * 32 /* low 16bits << 5 */
        SET @carry = @lo_16bit & 0x1F0000 /* move low 16bits carryover to hi 16bits */
        SET @carry = @carry / 0x10000 /* >> 16 */
        SET @hi_t = @hi_t + @carry
        SET @hi_t = @hi_t & 0xFFFF /* zero out overflow */

        /* + hash */
        SET @lo_16bit = @lo_16bit + @lo_t
        SET @hi_16bit = @hi_16bit + @hi_t + (@lo_16bit / 0x10000)
        /* delay clearing the overflow */

        /* ^c */
        SET @lo_16bit = @lo_16bit ^ @c

        /* Now clear the overflow bits */   
        SET @hi_16bit = @hi_16bit & 0xFFFF
        SET @lo_16bit = @lo_16bit & 0xFFFF

        SET @i = @i + 1
    END

    /* Do a sign extension of the hi-16bit if needed */
    IF (@hi_16bit & 0x8000 <> 0)
        SET @hi_16bit = 0xFFFF0000 | @hi_16bit

    /* Merge hi and lo 16bit back together */
    SET @hi_16bit = @hi_16bit * 0x10000 /* << 16 */
    SET @hash = @hi_16bit | @lo_16bit

    RETURN 0
GO

/*****************************************************************************/
    CREATE PROCEDURE dbo.TempGetAppID
    @appName    varchar(280),
    @appId      int OUTPUT
    AS
    SET @appName = LOWER(@appName)
    SET @appId = NULL

    SELECT @appId = AppId
    FROM [ASPState].dbo.ASPStateTempApplications
    WHERE AppName = @appName

    IF @appId IS NULL BEGIN
        BEGIN TRAN       

        SELECT @appId = AppId
        FROM [ASPState].dbo.ASPStateTempApplications WITH (TABLOCKX)
        WHERE AppName = @appName
        IF @appId IS NULL
        BEGIN
            EXEC GetHashCode @appName, @appId OUTPUT
            INSERT [ASPState].dbo.ASPStateTempApplications
            VALUES
            (@appId, @appName)
            IF @@ERROR = 2627
            BEGIN
                DECLARE @dupApp varchar(280)
                SELECT @dupApp = RTRIM(AppName)
                FROM [ASPState].dbo.ASPStateTempApplications
                WHERE AppId = @appId
                RAISERROR('SQL session state fatal error: hash-code collision between applications ''%s'' and ''%s''. Please rename the 1st application to resolve the problem.',
                            18, 1, @appName, @dupApp)
            END
        END

        COMMIT
    END

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempGetStateItem
    @id         nvarchar(88),
    @itemShort  varbinary(7000) OUTPUT,
    @locked     bit OUTPUT,
    @lockDate   datetime OUTPUT,
    @lockCookie int OUTPUT
AS
    DECLARE @textptr AS varbinary(max)
    DECLARE @length AS int
    DECLARE @now AS datetime
    SET @now = GETUTCDATE()

    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, @now),
        @locked = Locked,
        @lockDate = LockDateLocal,
        @lockCookie = LockCookie,
        @itemShort = CASE @locked
            WHEN 0 THEN SessionItemShort
            ELSE NULL
            END,
        @textptr = CASE @locked
            WHEN 0 THEN SessionItemLong
            ELSE NULL
            END,
        @length = CASE @locked
            WHEN 0 THEN DATALENGTH(SessionItemLong)
            ELSE NULL
            END
    WHERE SessionId = @id

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempGetStateItem2
    @id         nvarchar(88),
    @itemShort  varbinary(7000) OUTPUT,
    @locked     bit OUTPUT,
    @lockAge    int OUTPUT,
    @lockCookie int OUTPUT
AS
    DECLARE @textptr AS varbinary(max)
    DECLARE @length AS int
    DECLARE @now AS datetime
    SET @now = GETUTCDATE()

    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, @now),
        @locked = Locked,
        @lockAge = DATEDIFF(second, LockDate, @now),
        @lockCookie = LockCookie,
        @itemShort = CASE @locked
            WHEN 0 THEN SessionItemShort
            ELSE NULL
            END,
        @textptr = CASE @locked
            WHEN 0 THEN SessionItemLong
            ELSE NULL
            END,
        @length = CASE @locked
            WHEN 0 THEN DATALENGTH(SessionItemLong)
            ELSE NULL
            END
    WHERE SessionId = @id

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempGetStateItem3
    @id         nvarchar(88),
    @itemShort  varbinary(7000) OUTPUT,
    @locked     bit OUTPUT,
    @lockAge    int OUTPUT,
    @lockCookie int OUTPUT,
    @actionFlags int OUTPUT
AS
    DECLARE @textptr AS varbinary(max)
    DECLARE @length AS int
    DECLARE @now AS datetime
    SET @now = GETUTCDATE()

    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, @now),
        @locked = Locked,
        @lockAge = DATEDIFF(second, LockDate, @now),
        @lockCookie = LockCookie,
        @itemShort = CASE @locked
            WHEN 0 THEN SessionItemShort
            ELSE NULL
            END,
        @textptr = CASE @locked
            WHEN 0 THEN SessionItemLong
            ELSE NULL
            END,
        @length = CASE @locked
            WHEN 0 THEN DATALENGTH(SessionItemLong)
            ELSE NULL
            END,

        /* If the Uninitialized flag (0x1) if it is set,
           remove it and return InitializeItem (0x1) in actionFlags */
        Flags = CASE
            WHEN (Flags & 1) <> 0 THEN (Flags & ~1)
            ELSE Flags
            END,
        @actionFlags = CASE
            WHEN (Flags & 1) <> 0 THEN 1
            ELSE 0
            END
    WHERE SessionId = @id

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempGetStateItemExclusive
    @id         nvarchar(88),
    @itemShort  varbinary(7000) OUTPUT,
    @locked     bit OUTPUT,
    @lockDate   datetime OUTPUT,
    @lockCookie int OUTPUT
AS
    DECLARE @textptr AS varbinary(max)
    DECLARE @length AS int
    DECLARE @now AS datetime
    DECLARE @nowLocal AS datetime

    SET @now = GETUTCDATE()
    SET @nowLocal = GETDATE()
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, @now),
        LockDate = CASE Locked
            WHEN 0 THEN @now
            ELSE LockDate
            END,
        @lockDate = LockDateLocal = CASE Locked
            WHEN 0 THEN @nowLocal
            ELSE LockDateLocal
            END,
        @lockCookie = LockCookie = CASE Locked
            WHEN 0 THEN LockCookie + 1
            ELSE LockCookie
            END,
        @itemShort = CASE Locked
            WHEN 0 THEN SessionItemShort
            ELSE NULL
            END,
        @textptr = CASE Locked
            WHEN 0 THEN SessionItemLong
            ELSE NULL
            END,
        @length = CASE Locked
            WHEN 0 THEN DATALENGTH(SessionItemLong)
            ELSE NULL
            END,
        @locked = Locked,
        Locked = 1
    WHERE SessionId = @id

    RETURN 0    
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempGetStateItemExclusive2
    @id         nvarchar(88),
    @itemShort  varbinary(7000) OUTPUT,
    @locked     bit OUTPUT,
    @lockAge    int OUTPUT,
    @lockCookie int OUTPUT
AS
    DECLARE @textptr AS varbinary(max)
    DECLARE @length AS int
    DECLARE @now AS datetime
    DECLARE @nowLocal AS datetime

    SET @now = GETUTCDATE()
    SET @nowLocal = GETDATE()
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, @now),
        LockDate = CASE Locked
            WHEN 0 THEN @now
            ELSE LockDate
            END,
        LockDateLocal = CASE Locked
            WHEN 0 THEN @nowLocal
            ELSE LockDateLocal
            END,
        @lockAge = CASE Locked
            WHEN 0 THEN 0
            ELSE DATEDIFF(second, LockDate, @now)
            END,
        @lockCookie = LockCookie = CASE Locked
            WHEN 0 THEN LockCookie + 1
            ELSE LockCookie
            END,
        @itemShort = CASE Locked
            WHEN 0 THEN SessionItemShort
            ELSE NULL
            END,
        @textptr = CASE Locked
            WHEN 0 THEN SessionItemLong
            ELSE NULL
            END,
        @length = CASE Locked
            WHEN 0 THEN DATALENGTH(SessionItemLong)
            ELSE NULL
            END,
        @locked = Locked,
        Locked = 1
    WHERE SessionId = @id

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempGetStateItemExclusive3
    @id         nvarchar(88),
    @itemShort  varbinary(7000) OUTPUT,
    @locked     bit OUTPUT,
    @lockAge    int OUTPUT,
    @lockCookie int OUTPUT,
    @actionFlags int OUTPUT
AS
    DECLARE @textptr AS varbinary(max)
    DECLARE @length AS int
    DECLARE @now AS datetime
    DECLARE @nowLocal AS datetime

    SET @now = GETUTCDATE()
    SET @nowLocal = GETDATE()
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, @now),
        LockDate = CASE Locked
            WHEN 0 THEN @now
            ELSE LockDate
            END,
        LockDateLocal = CASE Locked
            WHEN 0 THEN @nowLocal
            ELSE LockDateLocal
            END,
        @lockAge = CASE Locked
            WHEN 0 THEN 0
            ELSE DATEDIFF(second, LockDate, @now)
            END,
        @lockCookie = LockCookie = CASE Locked
            WHEN 0 THEN LockCookie + 1
            ELSE LockCookie
            END,
        @itemShort = CASE Locked
            WHEN 0 THEN SessionItemShort
            ELSE NULL
            END,
        @textptr = CASE Locked
            WHEN 0 THEN SessionItemLong
            ELSE NULL
            END,
        @length = CASE Locked
            WHEN 0 THEN DATALENGTH(SessionItemLong)
            ELSE NULL
            END,
        @locked = Locked,
        Locked = 1,

        /* If the Uninitialized flag (0x1) if it is set,
           remove it and return InitializeItem (0x1) in actionFlags */
        Flags = CASE
            WHEN (Flags & 1) <> 0 THEN (Flags & ~1)
            ELSE Flags
            END,
        @actionFlags = CASE
            WHEN (Flags & 1) <> 0 THEN 1
            ELSE 0
            END
    WHERE SessionId = @id

    RETURN 0   
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempReleaseStateItemExclusive
    @id         nvarchar(88),
    @lockCookie int
AS
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, GETUTCDATE()),
        Locked = 0
    WHERE SessionId = @id AND LockCookie = @lockCookie

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempInsertUninitializedItem
    @id         nvarchar(88),
    @itemShort  varbinary(7000),
    @timeout    int
AS   

    DECLARE @now AS datetime
    DECLARE @nowLocal AS datetime
    SET @now = GETUTCDATE()
    SET @nowLocal = GETDATE()

    INSERT [ASPState].dbo.ASPStateTempSessions
        (SessionId,
         SessionItemShort,
         Timeout,
         Expires,
         Locked,
         LockDate,
         LockDateLocal,
         LockCookie,
         Flags)
    VALUES
        (@id,
         @itemShort,
         @timeout,
         DATEADD(n, @timeout, @now),
         0,
         @now,
         @nowLocal,
         1,
         1)

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempInsertStateItemShort
    @id         nvarchar(88),
    @itemShort  varbinary(7000),
    @timeout    int
AS   

    DECLARE @now AS datetime
    DECLARE @nowLocal AS datetime
    SET @now = GETUTCDATE()
    SET @nowLocal = GETDATE()

    INSERT [ASPState].dbo.ASPStateTempSessions
        (SessionId,
         SessionItemShort,
         Timeout,
         Expires,
         Locked,
         LockDate,
         LockDateLocal,
         LockCookie)
    VALUES
        (@id,
         @itemShort,
         @timeout,
         DATEADD(n, @timeout, @now),
         0,
         @now,
         @nowLocal,
         1)

    RETURN 0
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempInsertStateItemLong
    @id         nvarchar(88),
    @itemLong   varbinary(max),
    @timeout    int
AS   
    DECLARE @now AS datetime
    DECLARE @nowLocal AS datetime
    SET @now = GETUTCDATE()
    SET @nowLocal = GETDATE()

    INSERT [ASPState].dbo.ASPStateTempSessions
        (SessionId,
         SessionItemLong,
         Timeout,
         Expires,
         Locked,
         LockDate,
         LockDateLocal,
         LockCookie)
    VALUES
        (@id,
         @itemLong,
         @timeout,
         DATEADD(n, @timeout, @now),
         0,
         @now,
         @nowLocal,
         1)

    RETURN 0   
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempUpdateStateItemShort
    @id         nvarchar(88),
    @itemShort  varbinary(7000),
    @timeout    int,
    @lockCookie int
AS   
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, @timeout, GETUTCDATE()),
        SessionItemShort = @itemShort,
        Timeout = @timeout,
        Locked = 0
    WHERE SessionId = @id AND LockCookie = @lockCookie

    RETURN 0  
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempUpdateStateItemShortNullLong
    @id         nvarchar(88),
    @itemShort  varbinary(7000),
    @timeout    int,
    @lockCookie int
AS   
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, @timeout, GETUTCDATE()),
        SessionItemShort = @itemShort,
        SessionItemLong = NULL,
        Timeout = @timeout,
        Locked = 0
    WHERE SessionId = @id AND LockCookie = @lockCookie

    RETURN 0
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempUpdateStateItemLong
        @id         nvarchar(88),
        @itemLong   varbinary(max),
        @timeout    int,
        @lockCookie int
AS   
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, @timeout, GETUTCDATE()),
        SessionItemLong = @itemLong,
        Timeout = @timeout,
        Locked = 0
    WHERE SessionId = @id AND LockCookie = @lockCookie

    RETURN 0       
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempUpdateStateItemLongNullShort
    @id         nvarchar(88),
    @itemLong   varbinary(max),
    @timeout    int,
    @lockCookie int
AS   
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, @timeout, GETUTCDATE()),
        SessionItemLong = @itemLong,
        SessionItemShort = NULL,
        Timeout = @timeout,
        Locked = 0
    WHERE SessionId = @id AND LockCookie = @lockCookie

    RETURN 0          
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.TempRemoveStateItem
        @id     nvarchar(88),
        @lockCookie int
AS
    DELETE [ASPState].dbo.ASPStateTempSessions
    WHERE SessionId = @id AND LockCookie = @lockCookie
    RETURN 0  
GO
/*****************************************************************************/
CREATE PROCEDURE dbo.TempResetTimeout
    @id     nvarchar(88)
AS
    UPDATE [ASPState].dbo.ASPStateTempSessions
    SET Expires = DATEADD(n, Timeout, GETUTCDATE())
    WHERE SessionId = @id
    RETURN 0         
GO

/*****************************************************************************/
CREATE PROCEDURE dbo.DeleteExpiredSessions
AS
    DECLARE @now datetime
    SET @now = GETUTCDATE()

    DELETE [ASPState].dbo.ASPStateTempSessions
    WHERE Expires < @now

    RETURN 0         
GO

--/*****************************************************************************/

EXECUTE dbo.CreateTempTables
GO

DECLARE @sstype nvarchar(128)
SET @sstype = N'sstype_persisted'

IF UPPER(@sstype) = 'SSTYPE_TEMP' BEGIN
    DECLARE @cmd nchar(4000)

    SET @cmd = N'
        /* Create the startup procedure */
        CREATE PROCEDURE dbo.ASPState_Startup
        AS
            EXECUTE ASPState.dbo.CreateTempTables

            RETURN 0'
    EXEC(@cmd)
    EXECUTE sp_procoption @ProcName='dbo.ASPState_Startup', @OptionName='startup', @OptionValue='true'
END   

-- chrishayuk -- Commented out the creation of the DeleteExpiredSessions Job
--/*****************************************************************************/

--/* Create the job to delete expired sessions */

---- Add job category
---- We expect an error if the category already exists.
--PRINT 'If the category already exists, an error from msdb.dbo.sp_add_category is expected.'
--EXECUTE msdb.dbo.sp_add_category @name = N'[Uncategorized (Local)]'
--GO

--BEGIN TRANSACTION           
--    DECLARE @JobID BINARY(16) 
--    DECLARE @ReturnCode int   
--    DECLARE @nameT nchar(200)
--    SELECT @ReturnCode = 0    

--    -- Add the job
--    SET @nameT = N'ASPState' + '_Job_DeleteExpiredSessions'
--    EXECUTE @ReturnCode = msdb.dbo.sp_add_job
--            @job_id = @JobID OUTPUT,
--            @job_name = @nameT,
--            @owner_login_name = NULL,
--            @description = N'Deletes expired sessions from the session state database.',
--            @category_name = N'[Uncategorized (Local)]',
--            @enabled = 1,
--            @notify_level_email = 0,
--            @notify_level_page = 0,
--            @notify_level_netsend = 0,
--            @notify_level_eventlog = 0,
--            @delete_level= 0

--    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
--    -- Add the job steps
--    SET @nameT = N'ASPState' + '_JobStep_DeleteExpiredSessions'
--    EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep
--            @job_id = @JobID,
--            @step_id = 1,
--            @step_name = @nameT,
--            @command = N'EXECUTE DeleteExpiredSessions',
--            @database_name = N'ASPState',
--            @server = N'',
--            @database_user_name = N'',
--            @subsystem = N'TSQL',
--            @cmdexec_success_code = 0,
--            @flags = 0,
--            @retry_attempts = 0,
--            @retry_interval = 1,
--            @output_file_name = N'',
--            @on_success_step_id = 0,
--            @on_success_action = 1,
--            @on_fail_step_id = 0,
--            @on_fail_action = 2

--    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

--    EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1
--    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
--    -- Add the job schedules
--    SET @nameT = N'ASPState' + '_JobSchedule_DeleteExpiredSessions'
--    EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule
--            @job_id = @JobID,
--            @name = @nameT,
--            @enabled = 1,
--            @freq_type = 4,    
--            @active_start_date = 20001016,
--            @active_start_time = 0,
--            @freq_interval = 1,
--            @freq_subday_type = 4,
--            @freq_subday_interval = 1,
--            @freq_relative_interval = 0,
--            @freq_recurrence_factor = 0,
--            @active_end_date = 99991231,
--            @active_end_time = 235959

--    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
--    -- Add the Target Servers
--    EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(local)'
--    IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
--    COMMIT TRANSACTION         
--    GOTO   EndSave             
--QuitWithRollback:
--    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
--EndSave:
--GO

--/*************************************************************/
--/*************************************************************/
--/*************************************************************/
--/*************************************************************/

PRINT ''
PRINT '-------------------------------------------------'
PRINT 'Completed execution of InstallPersistSqlState.SQL'
PRINT '-------------------------------------------------'

Monday, 24 August 2009

Using SQL Azure Database in SQL Management Studio

OK, so I’ve figured it now. You can use SQL Azure Database in SQL Azure Management Studio, you just can’t use object explorer.

So this means you will be able to run queries but not be able to view stored proc lists, tables etc in the Object Explorer window. If you need to do that then you can always use Universal SQL Editor as described in my previous article

So the simplest way of doing this is to

  • When connected to your existing database
    • Click New Query button
    • Within Query Window
      • Right Click and Select Change Connection
        • Enter the server name (including ctp.database.windows.net e.g. servername.ctp.database.windows.net)
        • Select SQL Server Authentication
        • Enter Username (including servername, excluding ctp.database.windows.net e.g chris@servername
        • Enter Password
        • Click Options
          • In Connection Properties Tab
            • Change Connect to Database to database name (e.g. HawaiianShirts), just type it

This will allow you to run queries in SQL Management Studio but not use object explorer

Alternatively you can login as normal but disable object explorer

Tools->Options->(Environment->General)->At Startup = "Open New Query Window" instead of "Open Object Explorer"

Sunday, 23 August 2009

Connecting to SQL Azure Database with a management tool

Whilst working on my new book Azure in Action (first 3 chapters are available now online), I thought I’d write up how to connect to SQL Azure Database using a database browser tool.

If you are lucky enough to have received your SQL Azure Database invitation token you will have noticed that you cannot connect SQL Server Management Studio to your cloud database.

However this is not to say that you cannot use another tool to perform the same job.

Universal SQL Editor

The Tool I have used is Universal SQL Editor which has a 14 day trial and is a reasonable cost at $39 beyond that.  It’s a pretty good tool actually (please note I’m not affiliated with them in any way), it has intellisense and can talk to loads of different db types.

Setting up a DSN Connection

In the SQL Azure Portal I already created a database called “HawaiianShirts” which I will now connect to using the tool.  To do that I created a file DSN which points to my DB.  I called the DSN file “HawaiianShirts.dsn” and the contents of the DSN are below:

[ODBC]
DRIVER=SQL Server Native Client 10.0
UID=<myusername>@<myservername>
WSID=<mypcname>
APP=2007 Microsoft Office system
SERVER=<myservername>.ctp.database.windows.net
DATABASE=HawaiianShirts

So for example (not real data)

[ODBC]
DRIVER=SQL Server Native Client 10.0
UID=chris@a123456
WSID=CHRIS-PC
APP=2007 Microsoft Office system
SERVER=a123456.ctp.database.windows.net
DATABASE=HawaiianShirts

I can now use this file DSN to open a connection to the database.  I can use this editor to both create tables, stored procedures and view/edit data.

Here is a screenshot of me using the tool to edit some data in a table in SQL Azure Database

image

Thursday, 30 July 2009

Azure in Action book page up on Manning Site

I’m pleased to say that Manning have put up the page for our “Azure in Action” book on the Manning site.

Check it out at: http://www.manning.com/hay/

I will be posting up some details of the progress soon and some more details of how you can get early access to the chapters.

You can also check out our funky book cover

Wednesday, 29 July 2009

SQLBits

SQLBits which really is one of the top SQL Server conferences in the world is now accepting session submissions.

I had the pleasure of doing a session at SQL Bits 3 last year and I absolutely loved it.  Unfortunately since the timing is so close to the PDC, I don’t think I will be able to attend or present :(

However, if you are interested in submitting a session then you should go to the site

Even if you don’t want to submit a session you should make a note of the date in your diary and take a jaunt down to Wales (each conference is held in a different location in the UK).

Anyways check it out 19th-21st November 2009

Monday, 20 July 2009

Silverlight: iPhone Apps

So this was a tweet I picked up from @scottGu who picked it up from @techarch (by the way my twitter address is @chrishayuk)

So the Mono folks are working on a version of Mono that can compile to the iPhone which will eventually mean you will be able to run Silverlight Applications.

For more details see the MonoTouch Roadmap

This is absolute awesome as someone who has done a lot of Silverlight development and some iPhone development this is great news.

If you have ever tried to develop on the iPhone it’s like stepping back 10 years.  The prospect of being able to write C# / Silverlight code is just cool.

Once my book is complete this is one of the first set of technologies that I will be messing around, way cool.

Thursday, 9 July 2009

Silverlight: See you at Devlink

I’m very pleased to say that I will be spending a week in August at Nashville at Devlink

I’ve heard Nashville is an awesome place to be and I can’t wait to check it out.  I’ll be spending a few days before the conference chilling out and checking out the sites.  Hopefully I will get a chance to eat some good southern food and of course many many Cheeseburgers.

The attendee party looks great, I’ve never seen a baseball game before so I’m looking forward to it.  The conference agenda looks amazing with an incredible speaker line up. 

My session is on Silverlight Offline at 4.00pm on the Friday night.

It will be nice to concentrate on Silverlight again as I’ve been pretty Azure focused over the past few months :)

Looking forward to seeing you there, please say hello.

Wednesday, 8 July 2009

SQLBits V

This time it's in Wales and is lasting 3 days, with the third being a community day.  Wow it looks a cracker.

Its on Thursday 19th November to Saturday 21st (unfortunately PDC week but I will try and be back for it).

For more details visit SQLBits

I've taken the liberty of translating the official sqlbits v announcement translated from Welsh to English using an online translator below.

"We are being we ' heartburn pleased I announce be SQLBits crookedly go West , the rhandaliad he conferences SQLBits. We are being doing the happening he drives even morely and crookedly better na’a time last , in over 3 day with much more contain , except continuing I keep everything who is has worked as well crookedly the happenings previous. nferred the ddygwiddiad running he Thursday 19fed I Saturday 21ain November to the Celtic d to divine striped in Nghasnewydd , right Wales , nearly I ' group traffordd M4..) happening most yet , with contain gwethaf SQL Server. He will be en begin with day instruction before the happening , with details coming soon. We are being we has listened i’ch.) about happening evening time , ey tasted time self y had scorned we has planned day happening with tall signs Friday the 20few with theme SQL 2008 and R2. He will be Saturday 21fed crookedly day society usual , with speakers around the world speaking about text SQL Server"

Saturday, 4 July 2009

Modifying web.configs on the fly in Windows Azure

This has caught me out often enough that I should blog about it.

If you are working with a web role in Windows Azure your web project is copied into the bin directory of your cloud project and is ran from there.  This allows the Windows Azure Development environment to simulate running within the cloud.

If you need to therefore modify a web.config setting then modifying your web.config on the fly from your source file won’t make the slightest bit of difference.

You need to either modify the web.config in the bin directory of your cloud project, or stop and re-run your role again.

In my case, I was messing with the maxRequestLength attribute of the httpRuntime element.

Azure Pricing

So we will soon know the pricing model of Windows Azure (yay), we will probably find this out on the 13th of July but we will certainly know this by 4.30pm on Tuesday the 14th of July.

If we don’t have the information on this date then the folks attending session “SS006 – The Azure Service Platform Partner Model and Pricing” could be in for a surprise.  The Microsoft Worldwide Partner conference site has more details of this.  This session also seems to indicate that we may get pricing not just on Windows Azure but on SQL Data Services and .NET Services.

There are some other clues that we might be able to guess from the proposed session list.  One of the sessions (SS003) refers to Windows Azure, Business Edition.  This may mean that Microsoft may be offering different levels of service (and pricing) depending on your needs.  This could be good news for developers, maybe we will see a developer edition at some point :)

I can’t wait for this information as it will allow me to complete the section on pricing / SLA’s in the new book I am writing with Brian Prince for Manning titled “Azure in Action”.

Wednesday, 1 July 2009

Loosely couple code/data for static known types

So the title is a bit of a mouthful but I couldn't think of a better one.

The problem is simple and we have all faced it.  We have a database with static data that never or hardly changes.  The major issue we have is that we keep a copy of the data on the database and the we make loose runtime references to the code which can break our application.

For example lets say I have a payroll database.  Some employees are paid weekly, every 2 weeks or ever calendar month.  So I may choose to represent this data in a table called payfrequencytypes where i store my 3 rows.  From a database perspective this is cool.  I can join to this table, I can run reports etc.

From my application layer this is not so great.  If I wish to create some application business logic to determine when to pay my employee, I will need to check their pay frequency.  At this point I need to mix code and data, typically you will see something like

if (emp.PayFrequency == "Monthly")
    PayEmployee();

PayFequency types will never change so I want static compiler checking.  I really want my code to be something like

if (emp.PayFrequency == PayFrequencies.Monthly)
    PayEmployee();

This is much better for me at the app layer however the problem here is that I need to keep my 2 layers in sync now (app and code). 

I think code generation solves this problem.  Really we need to define in our application what static data we require, how we generate it the database and validation routines to make sure it is correct in the db.  We can then make our application responsible for generation and validation meaning we can feel sure that we can use static types

Obviously this example can get more complicated but you see the point.

I will try and put some code generation stuff when I have time that solves that issue for simple examples.

In the future I think this is exactly the sort of problem that Oslo could solve for us.

NULLS FIRST LAST

As I said in my previous post, I've been looking at other technologies in my continuing quest to become a better developer.

One technology is open source database called postgresql.  I haven't installed it yet just looking at the manuals and comparing to sql server.  Perhaps after the book is done I'll get a chance to play.

One of the features that I spotted that I think would pretty cool in SQL Server is the ability to specify sort order of nulls in SELECT statements.

By default in SQL Server nulls are returned first and it's a little nasty to return them last but in PostgreSQL it is easy.

SELECT Firstname, Surname
FROM Customers
ORDER BY Firstname NULLS LAST

In SQL Server you have to do some pretty nasty things that to get the same result.  Some folks often go for case statements or coalesces in the order statement to get a similar result.  I urge against this (hence why I am not showing you the code) as it produces inefficient query plans.  There are also other potential solutions that I am not going to go into (may'be another day),

My point is, I like this feature PostgreSQL has it, I think Oracle has it too and I think it might be a part of the SQL 2003 standard.  Whether it is standardized or not is a little fuzzy but I can't check as it costs lots of money to get a copy.  This leads me onto another point, the ISO standards should be free, end of story.

Finally if Microsoft are looking for a new T-SQL language feature to implement in the next version, this would be cool.

I think it meets the criteria of being something that is sufficiently hard to do and therefore should be covered in the core engine.

Tuesday, 30 June 2009

I’ve got lots to say just not enough time

I haven’t really spent anytime blogging in the past few months.  I have a tons of things to say, unfortunately just don’t have enough time at the moment.

I’ve obviously been writing my book on Azure and have loads to blog about regarding.

I’ve also spent time messing around with

    • design patterns
    • Data Layers
    • OR/M’s,
    • Caching

I’ve also been looking outside of the Microsoft stack which reaffirms my position of why I’m glad I work with Microsoft.  However it has broadened my horizons and realize there is a lot of cool stuff other folks in other platforms are doing.  Some of it the same, some of it different.

Specifically I was looking at:

  • Postgres
  • Objective C
  • IPhone development

I’m currently looking forward to .NET 4.0 (haven’t really played with it yet as I’ve been focused on the book).  The thing that excites me the most is ADO.NET Entity Framework 4.0.

I’ve also got a big list of things to play with once the first draft of the book is done.

I’m behind on loads of blogging and screencasts (especially with Silverlight).

Anyways I hope to be able to fit in some time soon and catch up with my blog posts.

It’s been a busy time.

If you’re interested in the book.

I’ve finished the first drafts of chapter 1 and chapter 5.  I’m nearly finished my first draft of chapter 4.  My co-author Brian Prince has finished his first draft of chapter 2 and has nearly finished his draft of chapter 3.

All in all we are nearly a third of the way through the book.

Saturday, 6 June 2009

Silverlight: (and Azure) Range Http Request Header

So this one is for the Azure team.

Can we have in Windows Azure Blob Storage the ability to pass through as an http request header key x-ms-range as well as range.

Both Silverlight and Flash don't allow the ability to pass the range in the header. I suspect that the NSAPI plug-in is preventing this. This means we can't make us of range downloads (and other functionality such as authorization) unless the Azure teams adds some extra support.

Thursday, 4 June 2009

Please make the classes in RestHelpers.cs public

There are a bunch of very cool set of helper classes (resthelpers.cs) in the Windows Azure storageclient library.

If these could be made public rather than internal my life would be so much happier

Blob Scenarios for the Azure in Action book

So I’m currently looking at the Blobs chapter of the “Azure in Action” book that myself and Brian Prince are writing.

In our call with the publisher the other night, our very cool publishing company (Manning) encouraged us to get as much input from folks in the community as possible.  I love this philosophy and I love working with such an enlightened company.

So if there any cool samples that you would love to see done, then please give me a shout.  We do have lots of cool scenarios and samples that I think will be particularly exciting, however I’m keen not to miss the mark on anything.

I hope to post a little bit more on some of the cool stuff in book, pretty soon.

Sunday, 24 May 2009

My new Azure Book

So I've just agreed to write a book on Azure for Manning.  The timeline is very aggressive so I'm going to pretty focused on Azure for the next few months.

I'm incredibly pleased and honored to have had my proposal accepted and today is my first day of writing.  Actually, when I say first day of writing, it's more of my first day setting up my environment for writing the book.

Today has so far consisted of:

  • Downloading lots of Software
  • Clearing up my desk
  • Uninstallaing and Installing Software

Anyways I will therefore pretty much exclusively focused on Azure rather than Silverlight for a few months, that's not to say that there is not some synergy in some areas.

I think the next few months will be a lot of fun but a lot of hard work.

The book should be available in all good bookstores (and some of the dodgy ones too) from January.

Anyways, enough waffling and back to some serious work.

Tuesday, 28 April 2009

Silverlight: Toronto Code Camp Slides + Samples

A big thanks to everyone who came to my session on Silverlight Communication at Toronto Code Camp.

Also a big mega thanks to everyone I met, and everyone involved in the organization.  What a great event.

My slides are available here and my samples are available here

Sunday, 19 April 2009

Silverlight: Multiple Http Requests Screencast

It's important to remember that Silverlight is a browser technology and is therefore subject to the limits imposed by the browser.

This is especially true in the networking stack and Silverlight is limited to the number of connections it can make just as the browser is.

I show you this is the case in my latest screencast, Multiple Http Requests in Silverlight

The video is embedded below for you to view also:


Saturday, 18 April 2009

Silverlight: Who cares if Binary Encoding is not interoperable?

I know the title of this post is a little tongue in cheek but actually who cares?

Just to put this in context in SL3, Microsoft have added support for binary encoding of soap messages for communication between Silverlight 3 applications and WCF Services.

Binary encoding means that the server can process messages faster, meaning higher throughput and the ability to handle more clients than the SL2 text encoding for SOAP.

The downside that the binary encoding is a proprietary Microsoft format (not MTOM), infact its the same one used by NetTCPBinding.

Since performance doesn't seem to be worse than text encoding in any situation, Microsoft have made this the default encoding for building Silverlight enabled WCF Services.

Does it matter if the default encoding is not interoperable?  No, because you can always set it back to a text encoding if you need interoperability.

Also, Silverlight by default does not encourage interoperability.  To allow other browser clients to connect to your webservice you need to set you cross domain policy file.  By default cross domain browser clients are shut out.

Finally if you are building a truly public interoperable api, you probably wouldn't make it SOAP based anyways, you would be likely to build a REST api

Good Move Microsoft, Binary Encoding Rocks!

I wish I was at WebDD

I have to admit, I wish I was at WebDD as an attendee or a speaker.

I decided not to submit a session (not because I didn't want to), but because I am working on my session for Toronto next week, which is the same reason I can't attend.

Looks like it was a cracking day, lots of webby things.

Thursday, 16 April 2009

Silverlight: Toronto Code Camp Session

I guess I’m getting a little excited about going to Toronto Code Camp next week.

At the same time, things are hectic, lots of preparation to do :)

I am presenting a session on Silverlight 3 Communication. Funnily enough although the title suggests that I will be focusing on the new Silverlight 3 WCF Features (which I will be), this is not the complete story.

In order to truly understand the improvements made to networking in Silverlight 3, you need to understand the networking stack as it relates to Silverlight, the design decisions made and the effects these decisions have on the Silverlight 2 networking story, and how some of these things have been resolved in Silverlight 3.

Finally having this understanding allows you to build better applications, allows you to design the right system, and to understand why you hit certain walls and how to get around them.

Since this stack is at the heart of all Silverlight networking, this means that if you are using technology such as .NET RIA Services, or ADO.NET Data Services for Silverlight, these core fundamentals ring true.

So as much as I cover the new features of SL3, more of the focus will be on the underlying networking stack and allowing you to understand the fundamentals. So this will help you both in Silverlight 2, Silverlight 3, and Silverlight of the Future.

Anyways, I’ve had a lot of fun building this presentation, and I hope you will enjoy the session at code camp.

I also plan to bring this session to the UK in June for NxtGenUG Fest09 :)

Hope to see you there

Monday, 13 April 2009

I'm a PC (thankfully)

This Easter bank holiday weekend, I decided I wanted to learn some new stuff.  So since I have been sporting my new IPhone for the last few weeks, I thought learning how to develop on the IPhone would be cool.

So I have borrowed my mates MacPowerbook Pro, and I picked some books on IPhone development and Objective-C.

I haven't developed any IPhone apps yet, as I thought I would concentrate on the Objective-C language, which I feel I have a good grip of now.

So later today, I will attempt to create my first IPhone application, however I just want to say one thing.  I am a PC (and thank God I am).

Using XCode, and Objective C is like taking a step back 7/8 years.  I so much prefer Visual Studio over XCode and I so much prefer C# over Objective-C.

Don't get me wrong I can see the influences of other languages (such as Objective-C) that have shaped C#, and I can see features in Objective-C that are now coming to C# or that I would love to see in C#, but I have to say I prefer C# and the .NET Framework.  I will probably expand up on this in future posts.

The one thing I want to say about Objective-C is that it is a little weird having to go back to explicit memory management (it really is like stepping in a time machine).  However at the same time it feels kind of nice, going back to the core (just not sure I would want to do this everyday).  I can easily see that with Mac Development most of your time will be spent thinking about Memory Management (which is just something we don't worry about so much these days).

Anyways, no matter what, after spending the weekend with Objective-C, I feel like a better developer but boy it makes me a appreciate Visual Studio, C# and the .NET Framework

Silverlight: Toronto Code Camp

I'm pleased to say that I will be presenting at Toronto Code Camp in a few weeks time.

I will be doing a session on Silverlight 3 communication, covering lots of WCF stuff, Local Messaging and the new networking api used for Out of Browser.

I'm really looking forward to my first trip to Canada and meeting lots of cool people.

I hope to see you there.

Friday, 10 April 2009

Enabling Hardware Virtualization on a Sony Laptop

This post is important to me as this was a real pain for me.

So virtualization is increasingly important today, and today I was needing to run a VM, and it turned out the VM was running a little slower than I was expecting.  This is because my laptop didn't have Virtualization enabled on the bios.

This is normally very simple, just go to your bios settings on bootup and enable it, however I own a Sony.  I love Sony Vaio's however you can't switch on hardware virtualization easily.

In the end I had to hack the bios (very scary).

To do this I created a boot disk on a usb stick (another painful thing), and then run the following tool from dos

symcmos.exe -L

I then opened the literal.txt file and changed register 0285 from 0000 to 0001 (using Edit in dos). 

I then ran

symcmos.exe -v2 -uliteral.txt

This register is specific to my laptop with BIOS (R2090J8) so unless you have the same bios it won't work.

I then powered off my laptop, and hardware virtualization was enabled.

The following posts were very useful to me:

http://www.linuxformat.gr/?q=content/how-unlock-and-enable-hardware-accelerated-virtualization-technology-vt-sony-vaio-laptop-and

http://forum.notebookreview.com/showthread.php?t=189228&page=14

If you have the same problem there is a lot to do, and it's very scary but it's worth it.  Don't follow my instructions literally as it might fry your laptop, and I'm not responsible for that.

Read the posts, and then decide to do what is best for you

Tuesday, 7 April 2009

Silverlight: DDD Belfast Silverlight 3 talk

A big thanks to everyone who came to my session at DDD Belfast on Silverlight 3 at the weekend.

I really enjoyed presenting in Belfast and I had a great a time all round, and glad that it went so well.  In the end I pretty much covered nearly every new feature of SL3 (which was a challenge).  I worked out that it took me about 80-100 hours to prepare that presentation.  So I think I will now take a few evenings off this week to relax.

The slides are available here:

http://cid-f6bb92b5df4cfec0.skydrive.live.com/browse.aspx/Public/Speaking/SL3Peek

A big thanks to Barry, Martha, Craig, Phil and everyone else I have missed out for putting together a great day.

Monday, 6 April 2009

Silverlight: Screencast: Silverlight 3 Derived Styles

In this short screencast, I show you how to quickly get started with style inheritance in Silverlight 3.

You can download the video from here, or watch below

Thursday, 2 April 2009

Demo Gremlins

So everytime I build a new presentation, I try and find an unsuspecting audience to try it out on before I present it for real.

I have a brand new presentation on Silverlight 3 in Belfast, and today I did my dummy run in Cambridge for a company that I work with.  They are a very forgiving audience :)

So I got really great feedback and it went really well (even though I was still changing things last night).  However the demo gods did strike on more than one occasion.  As I said they are very forgiving.

Again this proved how useful this strategy is, and on Saturday I will put the appropriate steps in place to stop the demo gremlins.

Just in case you are wondering Visual Studio 2008 and the Web Development Server kept locking up.  In the end I went for an open browser, building and refreshing (rather than clicking the play button).  This seemed to please the demo gods more.

I also discovered that doing a demo on network addresses changing (when you are not connected to a network), is not a clever thing to do.

Monday, 30 March 2009

Silverlight: SL3 Navigation Screencasts

In this first video, I show how to get started with the new Silverlight 3 Navigation feature.

 

In this second video, I show you how to use the new Uri Mapper and deep linking feature.