Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: state.sql file


Message #1 by =?us-ascii?Q?Fredrik_Normen?= <fredrik.normen@e...> on Wed, 11 Oct 2000 10:10:14 +0200
This is a multi-part message in MIME format.



------=_NextPart_000_0044_01C03369.1CA2AE20

Content-Type: text/plain;

	charset="us-ascii"

Content-Transfer-Encoding: 7bit



State.sql is a goof that we made with the preview release that we are

sheepishly embarrassed by.  We pointed everyone at the file, told them how

to run it, got it documented in the docs, and then dismissed people when

they said they "couldn't find it"......



...then we realized that we forgot to add it into setup -- and as such it

never made it out onto the pre-release bits....doh!



I've attached the state.sql file that we *intended* to ship in the

pre-release.  Run this against your SQL server, and then point your

config.web against the machine in order to store your session state in SQL.



One extra goof: in the pre-release your state server must have a username of

"sa" with no password (further doh!).  This will be fixed with the beta1

bits.



Sorry for the comedy of errors,



- Scott



/Fredrik Normen



------=_NextPart_000_0044_01C03369.1CA2AE20

Content-Type: application/octet-stream;

	name="state.sql"

Content-Transfer-Encoding: quoted-printable

Content-Disposition: attachment;

	filename="state.sql"



USE master

GO



IF DB_ID('ASPState') IS NOT NULL BEGIN

    DROP DATABASE ASPState

END

GO



CREATE DATABASE ASPState

GO



USE ASPstate

GO



CREATE PROCEDURE DropTempTables

AS

    IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name =3D 

'ASPStateTempSessions' AND type =3D 'U') BEGIN

        DROP TABLE tempdb..ASPStateTempSessions

    END



    IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name =3D 

'ASPStateTempApplications' AND type =3D 'U') BEGIN

        DROP TABLE tempdb..ASPStateTempApplications

    END



    RETURN 0

GO

   

CREATE PROCEDURE CreateTempTables

AS

    /*

     * Note that we cannot create user-defined data types in

     * tempdb because sp_addtype must be run in the context

     * of the current database, and we cannot switch to

     * tempdb from a stored procedure.

     */



    CREATE TABLE tempdb..ASPStateTempSessions (

        SessionId           CHAR(32)        NOT NULL PRIMARY KEY,

        Created             DATETIME        NOT NULL DEFAULT GETDATE(),

        Expires             DATETIME        NOT NULL,

        UnlockDate          DATETIME        NOT NULL,

        Timeout             INT             NOT NULL,

        Locked              BIT             NOT NULL,

        SessionItemShort    VARBINARY(7000) NULL,

        SessionItemLong     IMAGE           NULL,

    )



    CREATE TABLE tempdb..ASPStateTempApplications (

        AppId               INT             NOT NULL IDENTITY PRIMARY 

KEY,

        AppName             CHAR(280)       NOT NULL,

    )



    CREATE NONCLUSTERED INDEX Index_AppName ON 

tempdb..ASPStateTempApplications(AppName)



    RETURN 0

GO     



CREATE PROCEDURE RecreateTempTables

AS

    EXECUTE DropTempTables

    EXECUTE CreateTempTables

    RETURN 0

GO

  

EXECUTE RecreateTempTables

GO



EXECUTE sp_addtype tSessionId, 'CHAR(32)',  'NOT NULL'

GO



EXECUTE sp_addtype tAppName, 'VARCHAR(280)', 'NOT NULL'

GO



EXECUTE sp_addtype tSessionItemShort, 'VARBINARY(7000)'

GO



EXECUTE sp_addtype tSessionItemLong, 'IMAGE'

GO



EXECUTE sp_addtype tTextPtr, 'VARBINARY(16)'

GO



CREATE PROCEDURE TempGetAppId

    @appName    tAppName,

    @appId      INT OUTPUT

AS

    SELECT @appId =3D AppId

    FROM tempdb..ASPStateTempApplications

    WHERE AppName =3D @appName



    IF @appId IS NULL BEGIN

        INSERT tempdb..ASPStateTempApplications

            (AppName)

        VALUES

            (@appName)



        SELECT @appId =3D AppId

        FROM tempdb..ASPStateTempApplications

        WHERE AppName =3D @appName

    END



    RETURN 0

GO



CREATE PROCEDURE TempGetStateItem

    @id         tSessionId,

    @itemShort  tSessionItemShort OUTPUT,

    @locked     BIT OUTPUT,

    @unlockDate DATETIME OUTPUT

AS

    DECLARE @textptr AS tTextPtr

    DECLARE @length AS INT



    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE()),

        @itemShort =3D SessionItemShort,

        @textptr =3D TEXTPTR(SessionItemLong),

	@length =3D DATALENGTH(SessionItemLong),

        @locked =3D Locked,

        @unlockDate =3D UnlockDate,

        UnlockDate =3D DATEADD(s, 30, GETDATE())

    WHERE SessionId =3D @id

    IF @textptr IS NOT NULL BEGIN

        READTEXT tempdb..ASPStateTempSessions.SessionItemLong @textptr 0 

@length

    END



    RETURN 0

GO





CREATE PROCEDURE TempGetStateItemExclusive

    @id         tSessionId,

    @itemShort  tSessionItemShort OUTPUT,

    @locked     BIT OUTPUT,

    @unlockDate DATETIME OUTPUT

AS

    DECLARE @textptr AS tTextPtr

    DECLARE @length AS INT



    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE()),

        @itemShort =3D SessionItemShort,

        @textptr =3D TEXTPTR(SessionItemLong),

	@length =3D DATALENGTH(SessionItemLong),

        @locked =3D Locked,

        @unlockDate =3D UnlockDate,

        Locked =3D 1,

        UnlockDate =3D DATEADD(s, 30, GETDATE())

    WHERE SessionId =3D @id

    IF @textptr IS NOT NULL BEGIN

        READTEXT tempdb..ASPStateTempSessions.SessionItemLong @textptr 0 

@length

    END



    RETURN 0

GO



CREATE PROCEDURE TempReleaseStateItemExclusive

    @id         tSessionId

AS

    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE()),

        Locked =3D 0

    WHERE SessionId =3D @id



    RETURN 0

GO





CREATE PROCEDURE TempInsertStateItemShort

    @id         tSessionId,

    @itemShort  tSessionItemShort,

    @timeout    INT

AS   

    INSERT tempdb..ASPStateTempSessions

        (SessionId,

         SessionItemShort,

         Timeout,

         Expires,

         Locked,

         UnlockDate)

    VALUES

        (@id,

         @itemShort,

         @timeout,

         DATEADD(n, @timeout, GETDATE()),

         0,

         DATEADD(s, 30, GETDATE()))



    RETURN 0

GO



CREATE PROCEDURE TempInsertStateItemLong

    @id         tSessionId,

    @itemLong   tSessionItemLong,

    @timeout    INT

AS   

    INSERT tempdb..ASPStateTempSessions

        (SessionId,

         SessionItemLong,

         Timeout,

         Expires,

         Locked,

         UnlockDate)

    VALUES

        (@id,

         @itemLong,

         @timeout,

         DATEADD(n, @timeout, GETDATE()),

         0,

         DATEADD(s, 30, GETDATE()))



    RETURN 0

GO



CREATE PROCEDURE TempUpdateStateItemShort

    @id         tSessionId,

    @itemShort  tSessionItemShort,

    @timeout    INT

AS   

    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE()),

        SessionItemShort =3D @itemShort,

        Timeout =3D @timeout,

        Locked =3D 0

    WHERE SessionId =3D @id



    RETURN 0

GO



CREATE PROCEDURE TempUpdateStateItemShortNullLong

    @id         tSessionId,

    @itemShort  tSessionItemShort,

    @timeout    INT

AS   

    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE()),

        SessionItemShort =3D @itemShort,

        SessionItemLong =3D NULL,

        Timeout =3D @timeout,

        Locked =3D 0

    WHERE SessionId =3D @id



    RETURN 0

GO



CREATE PROCEDURE TempUpdateStateItemLong

    @id         tSessionId,

    @itemLong   tSessionItemLong,

    @timeout    INT

AS   

    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE()),

        SessionItemLong =3D @itemLong,

        Timeout =3D @timeout,

        Locked =3D 0

    WHERE SessionId =3D @id



    RETURN 0

GO



CREATE PROCEDURE TempUpdateStateItemLongNullShort

    @id         tSessionId,

    @itemLong   tSessionItemLong,

    @timeout    INT

AS   

    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE()),

        SessionItemLong =3D @itemLong,

        SessionItemShort =3D NULL,

        Timeout =3D @timeout,

        Locked =3D 0

    WHERE SessionId =3D @id



    RETURN 0

GO



CREATE PROCEDURE TempRemoveStateItem

    @id     tSessionId

AS

    DELETE tempdb..ASPStateTempSessions

    WHERE SessionId =3D @id

    RETURN 0

GO

           

CREATE PROCEDURE TempResetTimeout

    @id     tSessionId

AS

    UPDATE tempdb..ASPStateTempSessions

    SET Expires =3D DATEADD(n, Timeout, GETDATE())

    WHERE SessionId =3D @id

    RETURN 0

GO

           

CREATE PROCEDURE DeleteExpiredSessions

AS

    DECLARE @now DATETIME



    WHILE (1 =3D 1) BEGIN

        WAITFOR DELAY '000:01:00'



        SET @now =3D GETDATE()

        DELETE tempdb..ASPStateTempSessions

        WHERE Expires < @now

    END



    RETURN 0

GO

           

USE master

GO



DECLARE @PROCID int

SET @PROCID =3D OBJECT_ID('ASPState_Startup')

IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') =3D 1 

BEGIN

    DROP PROCEDURE ASPState_Startup

END

GO



CREATE PROCEDURE ASPState_Startup

AS

    EXECUTE ASPState..CreateTempTables

    EXECUTE ASPState..DeleteExpiredSessions



    RETURN 0

GO     



DECLARE @PROCID int

SET @PROCID =3D OBJECT_ID('EnableASPStateStartup')

IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') =3D 1 

BEGIN

    DROP PROCEDURE EnableASPStateStartup

END

GO



CREATE PROCEDURE EnableASPStateStartup

AS

    EXECUTE sp_procoption @procname=3D'ASPState_Startup', 

@optionname=3D'startup', @optionvalue=3D'true'

GO     



DECLARE @PROCID int

SET @PROCID =3D OBJECT_ID('DisableASPStateStartup')

IF @PROCID IS NOT NULL AND OBJECTPROPERTY(@PROCID, 'IsProcedure') =3D 1 

BEGIN

    DROP PROCEDURE DisableASPStateStartup

END

GO



CREATE PROCEDURE DisableASPStateStartup

AS

    EXECUTE sp_procoption @procname=3D'ASPState_Startup', 

@optionname=3D'startup', @optionvalue=3D'false'

GO     



EXECUTE EnableASPStateStartup

GO





------=_NextPart_000_0044_01C03369.1CA2AE20--




  Return to Index