Azure sql ELMAH DDL script

–~Changing index [dbo].[ELMAH_Error].PK_ELMAH_Error to a clustered index. You may want to pick a different index to cluster on.
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo]. [ELMAH_Error]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[ELMAH_Error](
[ErrorId] [uniqueidentifier] NOT NULL,
[Application] [nvarchar](60) NOT NULL,
[Host] [nvarchar](50) NOT NULL,
[Type] [nvarchar](100) NOT NULL,
[Source] [nvarchar](60) NOT NULL,
[Message] [nvarchar](500) NOT NULL,
[User] [nvarchar](50) NOT NULL,
[StatusCode] [int] NOT NULL,
[TimeUtc] [datetime] NOT NULL,
[Sequence] [int] IDENTITY(1,1) NOT NULL,
[AllXml] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_ELMAH_Error] PRIMARY KEY CLUSTERED
(
[ErrorId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF)
)
END

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ELMAH_Error]’) AND name = N’IX_ELMAH_Error_App_Time_Seq’)
CREATE NONCLUSTERED INDEX [IX_ELMAH_Error_App_Time_Seq] ON [dbo].[ELMAH_Error]
(
[Application] ASC,
[TimeUtc] DESC,
[Sequence] DESC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF)
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_ELMAH_Error_ErrorId]’) AND type = ‘D’)
BEGIN
ALTER TABLE [dbo].[ELMAH_Error] ADD CONSTRAINT [DF_ELMAH_Error_ErrorId] DEFAULT (newid()) FOR [ErrorId]
END

GO
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ELMAH_GetErrorsXml]’) AND type in (N’P’, N’PC’))
BEGIN
EXEC dbo.sp_executesql @statement = N’
CREATE PROCEDURE [dbo].[ELMAH_GetErrorsXml]
(
@Application NVARCHAR(60),
@PageIndex INT = 0,
@PageSize INT = 15,
@TotalCount INT OUTPUT
)
AS

SET NOCOUNT ON

DECLARE @FirstTimeUTC DATETIME
DECLARE @FirstSequence INT
DECLARE @StartRow INT
DECLARE @StartRowIndex INT

SELECT
@TotalCount = COUNT(1)
FROM
[ELMAH_Error]
WHERE
[Application] = @Application

— Get the ID of the first error for the requested page

SET @StartRowIndex = @PageIndex * @PageSize + 1

IF @StartRowIndex <= @TotalCount
BEGIN

SET ROWCOUNT @StartRowIndex

SELECT
@FirstTimeUTC = [TimeUtc],
@FirstSequence = [Sequence]
FROM
[ELMAH_Error]
WHERE
[Application] = @Application
ORDER BY
[TimeUtc] DESC,
[Sequence] DESC

END
ELSE
BEGIN

SET @PageSize = 0

END

— Now set the row count to the requested page size and get
— all records below it for the pertaining application.

SET ROWCOUNT @PageSize

SELECT
errorId = [ErrorId],
application = [Application],
host = [Host],
type = [Type],
source = [Source],
message = [Message],
[user] = [User],
statusCode = [StatusCode],
time = CONVERT(VARCHAR(50), [TimeUtc], 126) + ''Z''
FROM
[ELMAH_Error] error
WHERE
[Application] = @Application
AND
[TimeUtc] <= @FirstTimeUTC
AND
[Sequence] <= @FirstSequence
ORDER BY
[TimeUtc] DESC,
[Sequence] DESC
FOR
XML AUTO

'
END
GO
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ELMAH_GetErrorXml]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[ELMAH_GetErrorXml]
(
@Application NVARCHAR(60),
@ErrorId UNIQUEIDENTIFIER
)
AS

SET NOCOUNT ON

SELECT
[AllXml]
FROM
[ELMAH_Error]
WHERE
[ErrorId] = @ErrorId
AND
[Application] = @Application

'
END
GO
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo]. [ELMAH_LogError]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[ELMAH_LogError]
(
@ErrorId UNIQUEIDENTIFIER,
@Application NVARCHAR(60),
@Host NVARCHAR(30),
@Type NVARCHAR(100),
@Source NVARCHAR(60),
@Message NVARCHAR(500),
@User NVARCHAR(50),
@AllXml NVARCHAR(MAX),
@StatusCode INT,
@TimeUtc DATETIME
)
AS

SET NOCOUNT ON

INSERT
INTO
[ELMAH_Error]
(
[ErrorId],
[Application],
[Host],
[Type],
[Source],
[Message],
[User],
[AllXml],
[StatusCode],
[TimeUtc]
)
VALUES
(
@ErrorId,
@Application,
@Host,
@Type,
@Source,
@Message,
@User,
@AllXml,
@StatusCode,
@TimeUtc
)

'
END
GO

Advertisements

How to manage unhandled exception

Here is a small console application ;


using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace ConsoleApplication
{
    public static class Program
    {
    	static void Main()
    	{
    		AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;

    		Application.ThreadException += Application_ThreadException;
    		Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

    		Application.Run(new TestForm());

    		throw new Exception("Main");
    	}

    	static void Application_ThreadException(Object sender, ThreadExceptionEventArgs e)
    	{
    		MessageBox.Show(e.Exception.Message, "Application.ThreadException");
    	}

    	static void AppDomain_UnhandledException(Object sender, UnhandledExceptionEventArgs e)
    	{
    		MessageBox.Show(((Exception)e.ExceptionObject).Message, "AppDomain.UnhandledException");
    	}
    }

    public class TestForm : Form
    {
    	public TestForm()
    	{
    		this.Text = "Test Application";
    		this.ClientSize = new Size(200, 60);
    		this.MinimumSize = this.Size;
    		this.MaximumSize = this.Size;
    		this.StartPosition = FormStartPosition.CenterScreen;

    		Button btnThrowException = new Button();

    		btnThrowException.Text = "Throw";
    		btnThrowException.Location = new Point(0, 0);
    		btnThrowException.Size = new Size(200, 30);
    		btnThrowException.Click += (s, e) => { throw new Exception("Throw"); };

    		Button btnThrowExceptionOnOtherThread = new Button();

    		btnThrowExceptionOnOtherThread.Text = "Throw on other thread";
    		btnThrowExceptionOnOtherThread.Location = new Point(0, 30);
    		btnThrowExceptionOnOtherThread.Size = new Size(200, 30);
    		btnThrowExceptionOnOtherThread.Click += (s, e) => new Thread(() => { throw new Exception("Other thread"); }).Start();

    		this.Controls.Add(btnThrowException);
    		this.Controls.Add(btnThrowExceptionOnOtherThread);
    	}
    }
}

Text overflow end with three dots (…)

You are making a web application you have user name area and it’s css is like ;

(dummy css. The matter is here your username div has a width size.)

div.username{
width:40px;
height:20px;
.
.
.}

Your username div contains 25 character. When user changed his/her username to longer something. Now you have a problem. At this point you need to cut the text with three dots or something you want. You can write a helper method for this situation. Cut the character 25, but every character has different width and this solution is not efficient. You can use this css for text overflow ..

.cutLongText{
display: block;
white-space: nowrap;
text-overflow: ellipsis;
width: 100%;   /*or your div width */
overflow: hidden;}

much more variation for text-overflow visit here

Use jQuery to do something to a DIV when the user clicks outside of it

Sometimes you wanna do something such as when you click a div a part that you hide, shown and when click outside of if you wanna hide again . Following code do what exactly you want.

        $(document).mouseup(function (e) {

            var container = $("your_selector");
       
            if (!container.is(e.target) // if the target of the click isn't the container...
                && container.has(e.target).length === 0) // ... nor a descendant of the container
            {
                // do something you want (hide,show,remove, change class anything you want) Ex: container.hide()
               
            }
        });

using sql azure for session state

Sql azure have some differences so we have to create a new database and update store procedures.

CREATE DATABASE [ASPState]
GO

After created database called ASPState run the following script .

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

 Copyright Microsoft, Inc.
 All Rights Reserved.

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

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ASPStateTempSessions]') AND type in (N'U'))
DROP TABLE [dbo].[ASPStateTempSessions]
GO  

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ASPStateTempApplications]') AND type in (N'U'))
DROP TABLE [dbo].[ASPStateTempApplications]
GO  

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CREATE PROCEDURE dbo.GetMajorVersion
	@@ver int OUTPUT
AS
BEGIN
	DECLARE @version		nchar(100)
	DECLARE @dot			int
	DECLARE @hyphen		 int
	DECLARE @SqlToExec	 nchar(4000)

	SELECT @@ver = 7
	SELECT @version = @@Version
	SELECT @hyphen = CHARINDEX(N' - ', @version)
	IF (NOT(@hyphen IS NULL) AND @hyphen > 0)
	BEGIN
		SELECT @hyphen = @hyphen + 3
		SELECT @dot	= CHARINDEX(N'.', @version, @hyphen)
		IF (NOT(@dot IS NULL) AND @dot > @hyphen)
		BEGIN
			SELECT @version = SUBSTRING(@version, @hyphen, @dot - @hyphen)
			SELECT @@ver	 = CONVERT(int, @version)
		END
	END
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	 image		  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.TempGetVersion
	@ver	 char(10) OUTPUT
AS
	SELECT @ver = "2"
	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

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

DECLARE @cmd nchar(4000)

SET @cmd = N'
	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'
EXEC(@cmd)	
GO

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

CREATE PROCEDURE dbo.TempGetStateItem
	@id		 nvarchar(88),
	@itemShort varbinary(7000) OUTPUT,
	@locked	 bit OUTPUT,
	@lockDate  datetime OUTPUT,
	@lockCookie int OUTPUT
AS
	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,
		@length = CASE @locked
			WHEN 0 THEN DATALENGTH(SessionItemLong)
			ELSE NULL
			END
	WHERE SessionId = @id

	IF @length IS NOT NULL BEGIN
		SELECT [SessionItemLong] FROM [ASPState].dbo.ASPStateTempSessions WHERE SessionId = @id
	END

	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 @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,
		@length = CASE @locked
			WHEN 0 THEN DATALENGTH(SessionItemLong)
			ELSE NULL
			END
	WHERE SessionId = @id

	IF @length IS NOT NULL BEGIN
		SELECT [SessionItemLong] FROM [ASPState].dbo.ASPStateTempSessions WHERE SessionId = @id
	END

	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 @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,
		@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

	IF @length IS NOT NULL BEGIN
		SELECT [SessionItemLong] FROM [ASPState].dbo.ASPStateTempSessions WHERE SessionId = @id
	END

	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 @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,
		@length = CASE Locked
			WHEN 0 THEN DATALENGTH(SessionItemLong)
			ELSE NULL
			END,
		@locked = Locked,
		Locked = 1
	WHERE SessionId = @id

	IF @length IS NOT NULL BEGIN
		SELECT [SessionItemLong] FROM [ASPState].dbo.ASPStateTempSessions WHERE SessionId = @id
	END

	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 @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,
		@length = CASE Locked
			WHEN 0 THEN DATALENGTH(SessionItemLong)
			ELSE NULL
			END,
		@locked = Locked,
		Locked = 1
	WHERE SessionId = @id

	IF @length IS NOT NULL BEGIN
		SELECT [SessionItemLong] FROM [ASPState].dbo.ASPStateTempSessions WHERE SessionId = @id
	END

	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 @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,
		@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

	IF @length IS NOT NULL BEGIN
		SELECT SessionItemLong FROM [ASPState].dbo.ASPStateTempSessions WHERE SessionId = @id
	END

	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  image,
	@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  image,
	@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  image,
	@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

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

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



After all this add following tags to your web config

<system.web>
<sessionState 
mode="SQLServer" 
sqlConnectionString="
Server={your_server};
Database=ASPState;
User ID={your_user_id};
Password={your_password};
Trusted_Connection=False;
Encrypt=True;
Connection Timeout=30;" 
cookieless="false" 
timeout="54000" 
allowCustomSqlDatabase="true" />
</system.web>

That’s all you have to do.

Don’t scroll whole page while scrolling

-View-

<html>
  <head>
     <title>Title here</title>
  </head>
  <body>
      <div id="navbar" style="position:fixed;"></div>
      <div id="content>
      <div id="leftColumn"></div>
      <div id="centerColumn"></div>
      <div id="rightColumn"></div>    
  </div>
  </body>
</html>

-Javascript-

    $(window).scroll(function () {
        var scrollTop = $(window).scrollTop();
        if (scrollTop > 0)
            $('#leftColumn, #rightColumn').css('margin-top', scrollTop);
        else
            $('#leftColumn, #rightColumn').css('margin-top', scrollTop);
    });

P.S. Use this code if you just want to scroll center of the page Not left not right content just scroll center content of the page.

A union of two list

You can also use AddRange method.


var listB = new List<int>{3, 4, 5};  
var listA = new List<int>{1, 2, 3, 4, 5};

listA.AddRange(listB); // listA now has elements of listB also.

If you need new list (and exclude the duplicate), you can use union


  var listB = new List<int>{3, 4, 5};  
  var listA = new List<int>{1, 2, 3, 4, 5};
  var listFinal = listA.Union(listB);

If you need new list (and include the duplicate), you can use concat


  var listB = new List<int>{3, 4, 5};  
  var listA = new List<int>{1, 2, 3, 4, 5};
  var listFinal = listA.Concat(listB);