chandradineshbabu
asked on
MSG 3930 error in sqlserver2008
Hi,
I got the following error
Msg 3930, Sev 16, State 1, Line 29 : The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction. [SQLSTATE 42000].
the code is
CREATE PROCEDURE [dbo].[DBA_MaintenancePlan ]
@dbList varchar(1000) = null
,@AllDBs bit = 0
,@UserDBs bit = 0
,@SystemDBs bit = 0
,@excludeList varchar(1000) = null
,@BackupDB bit=0
,@BackupLog bit=0
,@INIT bit=0
,@DIFF bit=0
,@CHECKDB bit=0
,@CHECKCATALOG bit=0
,@CHECKALLOC bit=0
,@CHECK_COMPREHENSIVE bit=0
,@CHECK_DOW int = null
,@OPT_REFRESH bit=0
,@OPT_INDEXES bit=0
,@OPT_IndexFragThreshold float=5.0
,@OPT_IndexFillFactor int = 100
,@OPT_IndexOnlineOperation sOnly bit = 1
,@OPT_IndexBulkLogged bit = 0
,@OPT_IndexAutoLogBackup bit = 0
,@OPT_IndexAutoLogBackupIn tervalSecs int = 300
,@OPT_IndexMaxDurationMins int = 0
,@OPT_IndexTableRowLimit int = 0
,@OPT_STATISTICS bit=0
,@OPT_StatsRowModPct decimal(19,2) = 5.0
,@OPT_StatsIncludeCIXStats bit = 0
,@OPT_StatsIncludeCLStats bit = 0
,@OPT_StatsSamplePct int = 50
,@OPT_StatsDOW int = null
,@OPT_StatsMaxDurationMins int = 0
,@OPT_StatsTableRowLimit int = 0
,@OPT_IndexTableRowMin int = 0
,@OPT_StatsTableRowMin int = 0
AS BEGIN
SET NOCOUNT ON
CREATE TABLE #DB(id int identity, DBID int NOT NULL, name SYSNAME NOT NULL)
SELECT DBID, name
into #allDBs
FROM master.dbo.sysdatabases
WHERE 1=1
and name <> 'tempdb'
and @AllDBs = 1
SELECT DBID, name
into #systemDBs
FROM master.dbo.sysdatabases
WHERE 1=1
and name IN ('master', 'model', 'msdb', 'distribution')
and @SystemDBs = 1
SELECT DBID, name
into #userDBs
FROM master.dbo.sysdatabases
WHERE 1=1
and name NOT IN ('master', 'model', 'msdb', 'tempdb', 'distribution')
and @UserDBs = 1
INSERT INTO #DB(dbid, name)
select DBId, name
from #allDBs
WHERE name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList, ','))
UNION
select DBID, name
from #systemDBs
WHERE name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList, ','))
UNION
select DBID, name
from #userDBs
WHERE name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList, ','))
UNION
SELECT DBID,name
FROM master.dbo.sysdatabases
WHERE name IN (select rtrim(ltrim(Element)) from dbo.fn_Split(@dbList, ','))
and name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList, ','))
ORDER BY name
DECLARE @DBID int, @id int, @lastId int,
@Database sysname,
@rtn int,
@sqlstring nvarchar(250),
@setting char(10),
@Message nvarchar(1024),
@start_dow int,
@skip_check bit,
@skip_stats bit,
@compName varchar(100)
select @start_dow = DatePart(dw, GetDate()), @skip_check = 0, @skip_stats = 0
if (@check_dow is not null and @check_dow <> @start_dow) BEGIN
set @skip_check = 1
print 'Skipping database consistency checks. StartDOW:' + cast(@start_dow as varchar) + ', CheckDOW:' + cast(@check_dow as varchar)
end
if (@OPT_StatsDOW is not null and @OPT_StatsDOW <> @start_dow) BEGIN
set @skip_stats = 1
print 'Skipping statistic optimizations. StartDOW:' + cast(@start_dow as varchar) + ', StatsDOW:' + cast(@OPT_StatsDOW as varchar)
end
select @id = 1, @lastId = max(id) from #DB
WHILE (@id <= @lastId) BEGIN
SELECT @DBID = DBID, @Database = UPPER(name)
FROM #DB
WHERE ID = @id
set @id = @id + 1
set @compName = QUOTENAME(@@SERVERNAME) + '.' + @database
-- run any checks
BEGIN TRY
if ((@checkdb = 1 or @checkalloc = 1 or @checkcatalog = 1) and (@skip_check = 0)) BEGIN
EXEC @rtn = dba..DBA_CheckDatabase @database=@database
,@checkdb=@checkdb
,@checkalloc=@checkalloc
,@checkcatalog=@checkcatal og
,@check_comprehensive=@che ck_compreh ensive
IF (@rtn <> 0) BEGIN
CONTINUE
END
END
if (@OPT_REFRESH = 1) BEGIN
EXEC @rtn = dba..DBA_RefreshOptimizati onStatus @database=@database
END
if (@OPT_INDEXES = 1) BEGIN
EXEC @rtn = dba..DBA_PerformIndexOptim izations @database=@database
, @fragThreshold=@OPT_IndexF ragThresho ld
, @fillFactor=@OPT_IndexFill Factor
, @onlineOperationsOnly=@OPT _IndexOnli neOperatio nsOnly
, @bulkLogged=@OPT_IndexBulk Logged
, @autoLogBackup=@OPT_IndexA utoLogBack up
, @autoLogBackupIntervalSecs =@OPT_Inde xAutoLogBa ckupInterv alSecs
, @maxDurationMins = @OPT_IndexMaxDurationMins
, @tableRowLimit = @OPT_IndexTableRowLimit
, @tableRowMin = @OPT_IndexTableRowMin
END
if (@OPT_STATISTICS = 1 and @skip_stats = 0) BEGIN
EXEC @rtn = DBA_PerformStatisticOptimi zations @database=@database
, @rowModPct=@OPT_StatsRowMo dPct
, @includeCIXStats=@OPT_Stat sIncludeCI XStats
, @includeCLStats=@OPT_Stats IncludeCLS tats
, @samplePct=@OPT_StatsSampl ePct
, @maxDurationMins = @OPT_StatsMaxDurationMins
, @tableRowLimit = @OPT_StatsTableRowLimit
, @tableRowMin = @OPT_StatsTableRowMin
END
if (@BackupDB = 1) BEGIN
EXEC @rtn = dba..DBA_BackupDatabase @database=@database, @INIT=@INIT, @DIFF=@DIFF, @dow=@start_dow
IF (@rtn <> 0) BEGIN
CONTINUE
END
-- after a full or diff backup, the transaction log backup can be re-initialized to save space
if (@INIT = 1) BEGIN
exec @rtn = dba..DBA_BackupLog @database=@database, @INIT=1, @NOWARN=1, @dow=@start_dow
IF (@rtn <> 0) BEGIN
CONTINUE
END
END
END
ELSE if (@BackupLog = 1) BEGIN
exec @rtn = dba..DBA_BackupLog @database=@database, @INIT=@INIT, @dow=@start_dow
IF (@rtn <> 0) BEGIN
CONTINUE
END
END
END TRY
BEGIN CATCH
set @message = error_message()
exec master..usp_LogDBAError @compName, @message
IF (XACT_STATE()) = -1
BEGIN
ROLLBACK
END
CONTINUE
END CATCH
END -- while
RETURN 0
END
could you please modify above code send it to me
thanks in advance
I got the following error
Msg 3930, Sev 16, State 1, Line 29 : The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction. [SQLSTATE 42000].
the code is
CREATE PROCEDURE [dbo].[DBA_MaintenancePlan
@dbList varchar(1000) = null
,@AllDBs bit = 0
,@UserDBs bit = 0
,@SystemDBs bit = 0
,@excludeList varchar(1000) = null
,@BackupDB bit=0
,@BackupLog bit=0
,@INIT bit=0
,@DIFF bit=0
,@CHECKDB bit=0
,@CHECKCATALOG bit=0
,@CHECKALLOC bit=0
,@CHECK_COMPREHENSIVE bit=0
,@CHECK_DOW int = null
,@OPT_REFRESH bit=0
,@OPT_INDEXES bit=0
,@OPT_IndexFragThreshold float=5.0
,@OPT_IndexFillFactor int = 100
,@OPT_IndexOnlineOperation
,@OPT_IndexBulkLogged bit = 0
,@OPT_IndexAutoLogBackup bit = 0
,@OPT_IndexAutoLogBackupIn
,@OPT_IndexMaxDurationMins
,@OPT_IndexTableRowLimit int = 0
,@OPT_STATISTICS bit=0
,@OPT_StatsRowModPct decimal(19,2) = 5.0
,@OPT_StatsIncludeCIXStats
,@OPT_StatsIncludeCLStats bit = 0
,@OPT_StatsSamplePct int = 50
,@OPT_StatsDOW int = null
,@OPT_StatsMaxDurationMins
,@OPT_StatsTableRowLimit int = 0
,@OPT_IndexTableRowMin int = 0
,@OPT_StatsTableRowMin int = 0
AS BEGIN
SET NOCOUNT ON
CREATE TABLE #DB(id int identity, DBID int NOT NULL, name SYSNAME NOT NULL)
SELECT DBID, name
into #allDBs
FROM master.dbo.sysdatabases
WHERE 1=1
and name <> 'tempdb'
and @AllDBs = 1
SELECT DBID, name
into #systemDBs
FROM master.dbo.sysdatabases
WHERE 1=1
and name IN ('master', 'model', 'msdb', 'distribution')
and @SystemDBs = 1
SELECT DBID, name
into #userDBs
FROM master.dbo.sysdatabases
WHERE 1=1
and name NOT IN ('master', 'model', 'msdb', 'tempdb', 'distribution')
and @UserDBs = 1
INSERT INTO #DB(dbid, name)
select DBId, name
from #allDBs
WHERE name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList,
UNION
select DBID, name
from #systemDBs
WHERE name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList,
UNION
select DBID, name
from #userDBs
WHERE name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList,
UNION
SELECT DBID,name
FROM master.dbo.sysdatabases
WHERE name IN (select rtrim(ltrim(Element)) from dbo.fn_Split(@dbList, ','))
and name not in (select rtrim(ltrim(Element)) from dbo.fn_Split(@excludeList,
ORDER BY name
DECLARE @DBID int, @id int, @lastId int,
@Database sysname,
@rtn int,
@sqlstring nvarchar(250),
@setting char(10),
@Message nvarchar(1024),
@start_dow int,
@skip_check bit,
@skip_stats bit,
@compName varchar(100)
select @start_dow = DatePart(dw, GetDate()), @skip_check = 0, @skip_stats = 0
if (@check_dow is not null and @check_dow <> @start_dow) BEGIN
set @skip_check = 1
print 'Skipping database consistency checks. StartDOW:' + cast(@start_dow as varchar) + ', CheckDOW:' + cast(@check_dow as varchar)
end
if (@OPT_StatsDOW is not null and @OPT_StatsDOW <> @start_dow) BEGIN
set @skip_stats = 1
print 'Skipping statistic optimizations. StartDOW:' + cast(@start_dow as varchar) + ', StatsDOW:' + cast(@OPT_StatsDOW as varchar)
end
select @id = 1, @lastId = max(id) from #DB
WHILE (@id <= @lastId) BEGIN
SELECT @DBID = DBID, @Database = UPPER(name)
FROM #DB
WHERE ID = @id
set @id = @id + 1
set @compName = QUOTENAME(@@SERVERNAME) + '.' + @database
-- run any checks
BEGIN TRY
if ((@checkdb = 1 or @checkalloc = 1 or @checkcatalog = 1) and (@skip_check = 0)) BEGIN
EXEC @rtn = dba..DBA_CheckDatabase @database=@database
,@checkdb=@checkdb
,@checkalloc=@checkalloc
,@checkcatalog=@checkcatal
,@check_comprehensive=@che
IF (@rtn <> 0) BEGIN
CONTINUE
END
END
if (@OPT_REFRESH = 1) BEGIN
EXEC @rtn = dba..DBA_RefreshOptimizati
END
if (@OPT_INDEXES = 1) BEGIN
EXEC @rtn = dba..DBA_PerformIndexOptim
, @fragThreshold=@OPT_IndexF
, @fillFactor=@OPT_IndexFill
, @onlineOperationsOnly=@OPT
, @bulkLogged=@OPT_IndexBulk
, @autoLogBackup=@OPT_IndexA
, @autoLogBackupIntervalSecs
, @maxDurationMins = @OPT_IndexMaxDurationMins
, @tableRowLimit = @OPT_IndexTableRowLimit
, @tableRowMin = @OPT_IndexTableRowMin
END
if (@OPT_STATISTICS = 1 and @skip_stats = 0) BEGIN
EXEC @rtn = DBA_PerformStatisticOptimi
, @rowModPct=@OPT_StatsRowMo
, @includeCIXStats=@OPT_Stat
, @includeCLStats=@OPT_Stats
, @samplePct=@OPT_StatsSampl
, @maxDurationMins = @OPT_StatsMaxDurationMins
, @tableRowLimit = @OPT_StatsTableRowLimit
, @tableRowMin = @OPT_StatsTableRowMin
END
if (@BackupDB = 1) BEGIN
EXEC @rtn = dba..DBA_BackupDatabase @database=@database, @INIT=@INIT, @DIFF=@DIFF, @dow=@start_dow
IF (@rtn <> 0) BEGIN
CONTINUE
END
-- after a full or diff backup, the transaction log backup can be re-initialized to save space
if (@INIT = 1) BEGIN
exec @rtn = dba..DBA_BackupLog @database=@database, @INIT=1, @NOWARN=1, @dow=@start_dow
IF (@rtn <> 0) BEGIN
CONTINUE
END
END
END
ELSE if (@BackupLog = 1) BEGIN
exec @rtn = dba..DBA_BackupLog @database=@database, @INIT=@INIT, @dow=@start_dow
IF (@rtn <> 0) BEGIN
CONTINUE
END
END
END TRY
BEGIN CATCH
set @message = error_message()
exec master..usp_LogDBAError @compName, @message
IF (XACT_STATE()) = -1
BEGIN
ROLLBACK
END
CONTINUE
END CATCH
END -- while
RETURN 0
END
could you please modify above code send it to me
thanks in advance
ASKER
i need to use continue statement also.where should i use?
>> i need to use continue statement also.where should i use?
I didn't get your requirement..
The change which I suggested would have the logic like this
* Loop through records
* If any errors found, then it would rollback all changes done till now for all records
* Else commit the entire transaction.
Kindly let me know the logic which you try to implement so that I can change it out accordingly..
I didn't get your requirement..
The change which I suggested would have the logic like this
* Loop through records
* If any errors found, then it would rollback all changes done till now for all records
* Else commit the entire transaction.
Kindly let me know the logic which you try to implement so that I can change it out accordingly..
ASKER
the requirement is to skip the error found tramsaction and continue with other transaction.it means that it has to rollback only error found transaction and continue with other transaction.one more thing is that iam getting aboue error occasionally not all the times.this a dialy job and yesterday i found this error but today i didnt find it any more.my intention is that i need to resolve this issue even it is comming occasionally.
thanks in advance
thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this job have been running sucessfully for a while.let me monitor some more time before conclusion.
IF (XACT_STATE()) = -1
BEGIN
ROLLBACK
END
COMMIT
END CATCH
END -- while
RETURN 0
END