How to see sessions that are currently established in the database

set nocount on
SELECT @DBName = ‘databaseName’
begin try
drop table #tmpSpwho2
end try
begin catch
end catch
CREATE TABLE #tmpSpwho2 (SPID INT, Status VARCHAR(100), Login VARCHAR(100), HostName VARCHAR(100), Blkby VARCHAR(100), DBName VARCHAR(100), Command VARCHAR(50), CPUTime INT,
DiskIO INT, LastBatch VARCHAR(100), ProgramName VARCHAR(100), SPID2 INT, REQUESTID INT)

INSERT INTO #tmpSpwho2 EXEC sp_who2
select * FROM #tmpSpwho2 WHERE DBName = @DBName


LINQ and Deferred Execution

LINQ and Deferred Execution

This post covers one of the most important and frequently misunderstood LINQ features. Understanding deferred execution is a rite of passage that LINQ developers must undergo before they can hope to harness the full power of this technology. The contents of this post assumes an intermediate understanding of LINQ.