views:

199

answers:

1

SQL Server books online states the following about visibility (scope?) of temporary tables:

Temporary Tables
You can create local and global temporary tables. Local temporary tables are visible only in the current session; global temporary tables are visible to all sessions.

I want to understand how the scope of the global temporary table relates to an ADO.NET database connection. Will a global temp table created during an ADO.NET connection persist beyond that connection for future connections to use? What about parallel ADO.NET connections that start and stop together?

I'm not seeing the association between Microsoft's use of the word session in SQL context and the word connection in ADO.NET context, if they're one in the same or not.

A: 

they are the same, a connection gets a session SPID, the table should be there until it is dropped or you restart the sql server instance

in one window do this

create table ##temp ( ID int)
insert ##temp values (1)

now from another connection do this

select * from ##temp
SQLMenace
Am I interpreting correctly to understand that SQL Server might assign the same SPID to more than one ADO.NET connection?
John K
... but maybe different SPIDs to each connection in a different situation?
John K
no SPIDs are unique but they do get reused so if a connection comes in with SPID 61 then drops off and then someone else connects he might get 60, in general SPIDs below 51 and system connects and above 50 are user connections..you can run sp_who2 to see who is connected to your instance
SQLMenace