I have the following stored proc which uses a temp table to bulk import the data. I understand the temp tables are unique for every session, however i'm wondering if my application uses threads and makes multiple concurrent request to the stored proc, using the same sql connection from the application pool, will they end up referencing the same temp table?
CREATE PROCEDURE [dbo].[Mytestproc]
AS
BEGIN
BEGIN TRANSACTION
CREATE TABLE #Hold
(
ID INT,
VAL NVARCHAR(255)
)
BULK INSERT #Hold
FROM 'C:\data.txt'
WITH
(
FieldTermInAtOr ='|',
RowTermInAtOr ='\n'
)
SELECT *
FROM #Hold
DROP TABLE #Hold
COMMIT TRANSACTION
END
Whilst one thread is using a connection and executing this stored procedure, that same connection cannot be reused by the connection pool - so there's no danger of sharing there. Other threads cannot use this connection, and will open new ones instead.
In addition, there's no need to drop the temp table before the stored procedure ends - temp tables created within a stored proc are dropped automatically when the proc is exited.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With