Can Access pass-through queries see global temp tables on SQL Server created using ADO and/or SSMS?

后端 未结 1 641
抹茶落季
抹茶落季 2021-01-22 07:00

According to Microsoft\'s definition, \"Global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are refere

相关标签:
1条回答
  • 2021-01-22 07:19

    In reference to the title question...

    Can Access pass-through queries see global temp tables on SQL Server created using ADO and/or SSMS?

    ...my testing shows that the answer is "yes". Here's what I did:

    After restarting the SQL Server machine I logged in to Windows as Administrator and then logged in to SQL Server locally via SSMS (Windows Authentication). In SSMS I ran the script...

    USE [Accounting]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE ##gord(
        [ID] [int] IDENTITY(1,1) NOT NULL,
        [Name] [nvarchar](50) NULL,
     CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED 
    (
        [ID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    

    ...to create the global temp table, then I ran the script...

    INSERT INTO ##gord ([Name]) VALUES ('bar')
    

    ...to give it a row. Then, with SSMS still running I launched Access and ran the pass-through query...

    SELECT * FROM ##gord
    

    ...and it returned the row from the global temp table. I could keep running the pass-through query as long as SSMS was running, but as soon as I shut down SSMS the next attempt to run the Access pass-through query resulted in

    ODBC--call failed

    [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name '##gord'. (#208)

    In both the SSMS and the Access sessions I was connecting to the SQL Server as an Administrator (Server Role: sysadmin) so I'm wondering if perhaps you may have a SQL Server permissions issue that is preventing other sessions from seeing the global temp table.

    0 讨论(0)
提交回复
热议问题