SQL 2005 Tips --事务处理The current transaction cannot be committed and cannot support operations that write to the log file
2009-09-23 20:09
911 查看
Error Message:The current transaction cannot be committed and cannot support operations that write to the log file
1. Bad Way:
USE tempdb
GO
----(1)
CREATE TABLE TA(ID INT)
CREATE TABLE TB(ID INT)
GO
BEGIN TRY
BEGIN TRAN
INSERT TA SELECT 'TA'
COMMIT TRAN
END TRY
BEGIN CATCH
PRINT 'TranCount: ' + CONVERT(varchar(10),@@TRANCOUNT) + ' State:' + CONVERT(varchar(10),XACT_STATE())
INSERT TB SELECT 'TB'
ROLLBACK TRAN
END CATCH
GO
DROP TABLE TA
DROP TABLE TB
GO
Msg 3930, Level 16, State 1, Line 10
The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
这个问题,一般是由于在事务中,事务出现错误被CATCH到以后,在CATCH部分处理时,并没有及时回滚事务 而是在之前,又进行其他的操作,导致隐式事务提交和显式事务不能提交的冲突,从而抛出这样的错误信息。
2. Fixed:
USE tempdb
GO
CREATE TABLE TA(ID INT)
CREATE TABLE TB(ID INT)
GO
BEGIN TRY
BEGIN TRAN
INSERT TA SELECT 'TA'
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
--先把事务给回滚,再做其他操作
PRINT 'TranCount: ' + CONVERT(varchar(10),@@TRANCOUNT) + ' State:' + CONVERT(varchar(10),XACT_STATE())
INSERT TB SELECT 'TB'
END CATCH
GO
DROP TABLE TA
DROP TABLE TB
GO
You will get the message:
Msg 245, Level 16, State 1, Line 15
Conversion failed when converting the varchar value 'TB' to data type int.
/*
========================================================
========================================================
1. Bad Way:
USE tempdb
GO
----(1)
CREATE TABLE TA(ID INT)
CREATE TABLE TB(ID INT)
GO
BEGIN TRY
BEGIN TRAN
INSERT TA SELECT 'TA'
COMMIT TRAN
END TRY
BEGIN CATCH
PRINT 'TranCount: ' + CONVERT(varchar(10),@@TRANCOUNT) + ' State:' + CONVERT(varchar(10),XACT_STATE())
INSERT TB SELECT 'TB'
ROLLBACK TRAN
END CATCH
GO
DROP TABLE TA
DROP TABLE TB
GO
Msg 3930, Level 16, State 1, Line 10
The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
这个问题,一般是由于在事务中,事务出现错误被CATCH到以后,在CATCH部分处理时,并没有及时回滚事务 而是在之前,又进行其他的操作,导致隐式事务提交和显式事务不能提交的冲突,从而抛出这样的错误信息。
2. Fixed:
USE tempdb
GO
CREATE TABLE TA(ID INT)
CREATE TABLE TB(ID INT)
GO
BEGIN TRY
BEGIN TRAN
INSERT TA SELECT 'TA'
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
--先把事务给回滚,再做其他操作
PRINT 'TranCount: ' + CONVERT(varchar(10),@@TRANCOUNT) + ' State:' + CONVERT(varchar(10),XACT_STATE())
INSERT TB SELECT 'TB'
END CATCH
GO
DROP TABLE TA
DROP TABLE TB
GO
You will get the message:
Msg 245, Level 16, State 1, Line 15
Conversion failed when converting the varchar value 'TB' to data type int.
/*
========================================================
========================================================
相关文章推荐
- Cannot connect to WMI provider.You do not have permission or the server is unreachable.Note that you can only manager SQL Server 2005 and later version with SQL Server Configuration Manager.Invalid namespace [0x8004100e]
- to disable the entity lazy load, The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
- 2 Which of the following cannot be used as input to the SQL Tuning Advisor? (Choose all that apply.)
- 使用事务处理SQL数据时,遇到Exception:The transaction manager has disabled its support for remote/network transactions
- warning C4819: The file contains a character that cannot be represented in the current code page
- warning C4819: The file contains a character that cannot be represented in the current code page (93
- SQL Server 2005 RTM 安装错误 :The SQL Server System Configuration Checker cannot be executed due to
- The file contains a character that cannot be represented in the current code page (936)
- warning C4819: The file contains a character that cannot be represented in the current code page
- 今天进行svn的提交时出现的错误Cannot write to the prototype revision file of transaction
- The transaction log for database 'NJ_Address' is full. To find out why space in the log cannot be
- warning C4819: The file contains a character that cannot be represented in the current code page
- error C2220: warning treated as error - no 'object' file generated warning C4819: The file contains a character that cannot be represented in the current code page (936).
- Error 1406. Setup cannot write the value DisableExceptionChainValidation to the registry key \SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File
- BI Java 补丁错误处理 :Cannot login to the SAP J2EE Engine using user and password as provided in the Filesystem Secure Store. Enter va
- SQL Server 2005 RTM 安装错误 :The SQL Server System Configuration Checker cannot be executed due to
- The file contains a character that cannot be represented in the current code page
- warning C4819: The file contains a character that cannot be represented in the current code page
- Database 'xxx' cannot be upgraded because it is read-only or has read-only file Make the database or files writeable, and rerun recovery.
- VSE: The file contains a character that cannot be represented in the current code page (936).