2012-01-19 5 views
0

아래 스크립트를 실행하면이 예외가 발생합니다. 약 20 분 후 (+/- 2 분) 추락했습니다. 일괄 처리를 만들지 않고이 예외를 방지하려면 어떻게해야합니까? 나는 그것을 필요로하는 모든 고객 기록을 위해 이것을하고 싶다.SQL 변환 스크립트로 인해 System.OutOfMemoryException이 발생합니다.

예외 :

An error occurred while executing batch. Error message is: Exception of type 'System.OutOfMemoryException' was thrown. 

SQL 변환 스크립트 : 내 의견에 언급 된 2 저장 프로 시저에서

SELECT clientid 
INTO #Temp 
FROM client 

DECLARE 
    @iteratorId INT, 
    @phone NVARCHAR(64), 
    @fax NVARCHAR(64), 
    @contactid INT 

WHILE (SELECT Count(*) FROM #Temp) > 0 
BEGIN 

    SELECT TOP 1 @iteratorId = clientid FROM #Temp 
    SET @contactid = NULL 

    --try and grab the first non null phone number in priority order 
    SET @phone = ISNULL((
     SELECT TOP 1 
      dayphone 
     FROM contact c 
     INNER JOIN dbo.clientcontact cc ON c.contactid = cc.contactid 
     WHERE 
      clientid = @iteratorId 
      AND cc.contacttypeid=2 
      AND c.dayphone IS NOT NULL 
     ORDER BY cc.parentclientcontactid, priority DESC 
    ),'') 

    --try and grab the first non null fax priority order 
    SET @fax = ISNULL((
     SELECT TOP 1 
      fax 
     FROM contact c 
     INNER JOIN dbo.clientcontact cc ON c.contactid = cc.contactid 
     WHERE 
      clientid = @iteratorId 
      AND cc.contacttypeid=2 
      AND c.fax IS NOT NULL 
     ORDER BY cc.parentclientcontactid, priority DESC 
    ),'') 

    IF NOT EXISTS(SELECT * FROM clientcontact WHERE [email protected] AND contacttypeid=3 AND priority=1) 
    BEGIN  
     INSERT INTO dbo.contact 
       (versionnumber , 
        createdate , 
        firstname , 
        lastname , 
        title , 
        middleinitial , 
        dayphone , 
        nightphone , 
        mobilephone , 
        fax , 
        securefax , 
        extranetusername , 
        extranetpassword , 
        email , 
        active , 
        testfaxpagereceived , 
        ftpoptionid , 
        testresultnotify 
       ) 
     VALUES (0 , -- versionnumber - int 
        GETDATE() , -- createdate - datetime 
        NULL , -- firstname - nvarchar(64) 
        NULL , -- lastname - nvarchar(64) 
        NULL , -- title - nvarchar(64) 
        NULL , -- middleinitial - nvarchar(64) 
        NULL , -- dayphone - nvarchar(64) 
        NULL , -- nightphone - nvarchar(64) 
        NULL , -- mobilephone - nvarchar(64) 
        NULL , -- fax - nvarchar(64) 
        '' , -- securefax - bit 
        NULL , -- extranetusername - nvarchar(64) 
        NULL , -- extranetpassword - nvarchar(64) 
        NULL , -- email - nvarchar(127) 
        0 , -- active - bit 
        0 , -- testfaxpagereceived - bit 
        NULL , -- ftpoptionid - int 
        NULL -- testresultnotify - bit 
       ) 
     SET @contactid = @@IDENTITY 

     EXEC dbo.procContactSave 
      @contactid = @contactid, -- int 
      @firstname = "General", -- nvarchar(64) 
      @middleinitial = NULL, -- nvarchar(64) 
      @nightphone = NULL, -- nvarchar(64) 
      @lastname = "Info", -- nvarchar(64) 
      @email = NULL, -- nvarchar(127) 
      @fax = @fax, -- nvarchar(64) 
      @testfaxpagereceived = 0, -- bit 
      @mobilephone = NULL, -- nvarchar(64) 
      @securefax = 0, -- bit 
      @active = 1, -- bit 
      @extranetpassword = NULL, -- nvarchar(64) 
      @extranetusername = NULL, -- nvarchar(64) 
      @title = NULL, -- nvarchar(64) 
      @ftpoptionid = NULL, -- int 
      @dayphone = @phone, -- nvarchar(64) 
      @testresultnotify = 0, -- bit 
      @audituserid = 0 -- int 

     EXEC dbo.procClientContactSave 
      @clientcontactid = NULL, -- int 
      @priority = 1, -- int 
      @clientid = @iteratorId, -- int 
      @contacttypeid = 3, -- int 
      @contactid = @contactid, -- int 
      @audituserid = 0 -- int 
    END 

    DELETE #Temp Where clientid = @iteratorId -- delete row so we don't loop over it again 
END 
DROP TABLE #Temp 
+1

'dbo.procContactSave'와'dbo.procClientContactSave'는 어떤 CLR 기능을 사용하고 있습니까? – Lucero

+0

그냥 저장 프로 시저 .. 그 명령을 주로 삽입 – MacGyver

+0

그 저장된 프로 시저는 SQL 결과를 1 결과 집합을 모두 설정합니다. 그게 SSMS의 메모리가 다 떨어지는 원인이 될까요? SQL-Server-2008의 메모리 부족 현상은 이상하게 보입니다. 단일 스크립트로 11,000 개의 레코드를 처리 할 수 ​​있다고 생각합니다. – MacGyver

답변

0

, 나는 기록을 삽입 표준 웹 응용 프로그램 저장 프로 시저를 호출뿐만 아니라했다 스크립트의 각 반복에 대한 결과 세트 (단 1 레코드 포함)에 해당 레코드를 리턴했습니다. 이 스크립트는 1.5 분 동안 실행되었는데,이 두 저장 프로 시저의 SELECT 문에 주석을 달았 기 때문에 SSMS가 결과 집합에서 표시 한 데이터의 양이 부숴 졌다고 상상합니다. 이로 인해 추락 사고가 발생하지 않았습니다 (20 분 이상 1.5 분 미만).

관련 문제