Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 无法提交当前事务,并且无法支持写入日志文件的操作。回滚事务_Sql Server - Fatal编程技术网

Sql server 无法提交当前事务,并且无法支持写入日志文件的操作。回滚事务

Sql server 无法提交当前事务,并且无法支持写入日志文件的操作。回滚事务,sql-server,Sql Server,在SQL Server 2008中运行脚本时遇到此错误。但当我在SQL Server 2012中恢复数据库时,它成功运行,我没有遇到任何错误 无法提交当前事务,并且无法支持写入日志文件的操作。回滚事务 以下是我的存储过程: CREATE PROCEDURE UpdateDependentViews ( @TableName NVARCHAR(128), @All

在SQL Server 2008中运行脚本时遇到此错误。但当我在SQL Server 2012中恢复数据库时,它成功运行,我没有遇到任何错误

无法提交当前事务,并且无法支持写入日志文件的操作。回滚事务

以下是我的存储过程:

CREATE PROCEDURE UpdateDependentViews  
(                                                              
 @TableName NVARCHAR(128),  
 @AllDependents bit = 1  
)                           
AS                                                              
    SET NOCOUNT ON;

    CREATE TABLE #Dependencies
    (
       [Counter] [int] IDENTITY(1,1) NOT NULL,
       [View_Name] [nvarchar](128),                          
    ) ON [PRIMARY];

    CREATE INDEX Counter ON #Dependencies(Counter);

    /* Get the first degree dependent views. */  
    INSERT INTO #Dependencies(View_Name)  
       SELECT V.[name] AS [View_Name]  
       FROM sys.sql_expression_dependencies SD  
       INNER JOIN sys.views V ON SD.referencing_id = V.object_id  
       INNER JOIN sys.objects D ON SD.referenced_id = D.object_id  
       WHERE SD.referencing_minor_id = 0  
         AND SD.referenced_minor_id = 0  
         AND SD.referencing_class = 1   
         AND D.type IN ('U', 'V')  
         AND D.is_ms_shipped = 0  
         AND V.is_ms_shipped = 0  
         AND D.[name] = @TableName  

    SELECT * 
    FROM sys.sql_expression_dependencies  
    WHERE referenced_entity_name IS NULL  

    /* Refresh the dependent views. */                          
    DECLARE @ViewName NVARCHAR(128)                          
    DECLARE @Counter INT  
SET @Counter = 1;  
DECLARE @Errors NVARCHAR(MAX)  
SET @Errors = ''  
WHILE EXISTS (SELECT [View_Name] FROM #Dependencies WHERE Counter = @Counter)                      
BEGIN                      
 SELECT @ViewName = View_Name FROM #Dependencies WHERE Counter = @Counter;                      
 /*Get Inner view dependencies */                      
 IF ISNULL(@AllDependents, 0) = 1   
 BEGIN     
  IF ISNULL(@AllDependents, 0) = 1 AND EXISTS(SELECT 1   
             FROM sys.sql_expression_dependencies SD   
             INNER JOIN sys.objects D ON SD.referenced_id =  D.object_id  
             WHERE SD.referencing_minor_id = 0  
              AND SD.referenced_minor_id = 0  
              AND SD.referencing_class = 1  
              AND D.type IN ('U', 'V')  
              AND D.is_ms_shipped = 0  
              AND D.[name] = @ViewName)  
  BEGIN  
   INSERT INTO #Dependencies(View_Name)  
   SELECT V.[name] AS [View_Name]  
   FROM sys.sql_expression_dependencies SD  
   INNER JOIN sys.views V  
    ON SD.referencing_id =  V.object_id  
   INNER JOIN sys.objects D  
    ON SD.referenced_id =  D.object_id  
   WHERE SD.referencing_minor_id = 0  
    AND SD.referenced_minor_id = 0  
    AND SD.referencing_class = 1   
    AND D.type IN ('U', 'V')  
    AND D.is_ms_shipped = 0  
    AND V.is_ms_shipped = 0  
    AND ISNULL(D.[name], '') <> ''    
    AND D.[name] = @ViewName  
    AND V.[name] NOT IN (SELECT View_Name FROM #Dependencies )        
  END  
 END;  

 /* Refresh the view */   
 BEGIN TRY  
     --BEGIN TRANSACTION  
  EXEC SP_REFRESHVIEW @ViewName  
  --COMMIT TRANSACTION    
 END TRY  
 BEGIN CATCH  
     --ROLLBACK TRANSACTION  
  IF EXISTS (SELECT 1 FROM [ISSIMODEL(15)].sys.objects WHERE [name] = @ViewName)  
   SET @Errors = @Errors + CHAR(13) + 'Error: Failed to RefreshView ' + @ViewName + '. Message: ' + ERROR_MESSAGE()   
 END CATCH  

 SET @Counter = @Counter + 1;  
END;  
IF ISNULL(@Errors, '') <> ''  
 RAISERROR (@Errors, 16, 1)  

DROP TABLE #Dependencies;  

在代码中使用TRY\CATCH块时,通常会发生这种情况: 确保代码中包含此流:

DECLARE @ErrorMum INT 
DECLARE @ErrorMessage VARCHAR(200) 
DECLARE @Severity INT 
DECLARE @State INT 

BEGIN TRY

    BEGIN TRAN T1

    <Your Code goes here>

    COMMIT TRAN T1 
END TRY

BEGIN CATCH
    IF @@TRANCOUNT > 0 BEGIN 
    ROLLBACK TRAN T1 
    END

    SET @ErrorMum = ERROR_NUMBER()
    SET @ErrorMessage = ERROR_MESSAGE()
    SET @Severity = ERROR_SEVERITY()
    SET @State = ERROR_STATE()

    RAISERROR(@ErrorMessage, @Severity, @State)
END CATCH

您没有提供足够的信息来做出任何结论。您可以发布导致此问题的脚本吗?我在运行脚本时遇到此错误-帮助我们帮助您,请发布您的脚本。