1

저장 프로 시저를 실행하려고합니다. SP에서는 두 개의 테이블 변수를 만듭니다 (3 개의 CTE를 사용하여). 그런 다음 두 테이블을 조인하고 기존 테이블에 INSERT INTO를 입력하십시오. 나는 계속 오류를 얻지 못한다. 자물쇠 자원을 얻을 수 없다. 어떻게하면이 문제를 해결할 수 있을까요? 그것이 나의 SP를 쓴 방법입니까?SQL Server 데이터베이스 엔진 인스턴스가 현재 LOCK 리소스를 가져올 수 없으므로 더 많은 리소스를 확보 할 수 없습니다.

ALTER PROCEDURE [dbo].[CreateDailyAttribution] 
-- Add the parameters for the stored procedure here 
@day1 varchar(10) 
,@day2 varchar(10) 
AS 
BEGIN 
-- SET NOCOUNT ON added to prevent extra result sets from 
-- interfering with SELECT statements. 
SET NOCOUNT ON; 

DECLARE @tableUnrealized as table 
(
    POFFIC varchar(3) 
    ,PACCT varchar(5) 
    --,PATYPE varchar(3) 
    ,PSDSC1 varchar(100) 
    ,ShortDesc varchar(100) 
    ,ChangeInOTE decimal(18,0) 
    ,tMinus1_Qty integer 
    ,tMinus2_Qty integer 
    ,Sector varchar(50) 
); 

DECLARE @tableRealized as table 
(
    POFFIC varchar(3) 
    ,PACCT varchar(5) 
    --,PATYPE varchar(3) 
    ,PSDSC1 varchar(100) 
    ,ShortDesc varchar(100) 
    ,Realized decimal(18,0) 
    ,Sector varchar(50) 
); 

답변

1

당신이지고있어 오류는 서버가 충분한 물리적 메모리를 사용할 수 있기 때문에, 충분한 메모리가 서버에서 사용하도록 허용하거나, 메모리가 부족하거나 다른 프로세스가 너무 사용하고 있음을 나타냅니다 많은 메모리와 SQL은 충분한 호흡 공간이 없습니다.

메모리를 많이 사용할 수있는 것처럼 보입니다. @table 변수보다는 #temp 테이블을 사용하는 것이 좋고 메모리가 부족한 지 확인하는 것이 좋습니다 (#temp 테이블은 tempdb에 들어가서 디스크에 충돌하지만 테이블 변수는 메모리에 저장 될 수 있습니다.) 데이터에 대해 더 많이 알지 않고 쿼리에 대한 깊이있는 분석 없이는 말하기가 정말 어렵습니다.

MSDN에 대한 몇 가지 추가 조언이 있습니다. 이 오류 :

Explanation

SQL Server cannot obtain a lock resource. This can be caused by either of the following reasons:

  • SQL Server cannot allocate more memory from the operating system, either because other processes are using it, or because the server is operating with the max server memory option configured.
  • The lock manager will not use more than 60 percent of the memory available to SQL Server.

User Action

If you suspect that SQL Server cannot allocate sufficient memory, try the following:

  • If applications besides SQL Server are consuming resources, try stopping these applications or consider running them on a separate server. This will remove release memory from other processes for SQL Server.
  • If you have configured max server memory, increase max server memory setting.

If you suspect that the lock manager has used the maximum amount of available memory identify the transaction that is holding the most locks and terminate it.

The following script will identify the transaction with the most locks:

SELECT request_session_id, COUNT (*) num_locks 
FROM sys.dm_tran_locks 
GROUP BY request_session_id 
ORDER BY count (*) DESC 

Take the highest session id, and terminate it using the KILL command.

+0

감사합니다! ... #tempTables로 변경되면 결국 작동합니다. – solarissf