English 中文(简体)
Sql 服务器。 当前交易无法进行, 无法支持写入日志文件的操作
原标题:Sql server. The current transaction cannot be committed and cannot support operations that write to the log file
begin tran begin try select case when 1=0 then 0.0 else end --this will not work end try begin catch --error has occured. But it doesnt matter. We want to continue anyway end catch select 1 --do something else commit --unfortunatelly this producess error "The current transaction cannot be committed and cannot support operations that write to the log file" What can I do to commit transaction? I know, select case when 1=0 then 0.0 else end is incorrect. Thats why it is in try/catch block (in real situations this is query defined by administrator). But I want to commit the rest of operations. Edit:// The code works as I wanted if the "Incorrect query" is for example select 1/0 begin tran begin try select 1/0-- this will not work end try begin catch --error has occured. But it doesnt matter. We want to continue anyway end catch select 1--do something else commit --commit is done without any errors
问题回答
From this page: "If an error generated in a TRY block causes the state of the current transaction to be invalidated, the transaction is classified as an uncommittable transaction. An error that ordinarily ends a transaction outside a TRY block causes a transaction to enter an uncommittable state when the error occurs inside a TRY block. An uncommittable transaction can only perform read operations or a ROLLBACK TRANSACTION." From this page: "SQL Server can tolerate some errors inside a transaction without it having to be marked as un-committable. For example SELECT 1/0 would cause an error but not force a transaction into an un-committable state."
you could try checking the transaction state before you commit or exit.. begin tran begin try select case when 1=0 then 0.0 else end --this will not work end try begin catch --error has occured. But it doesnt matter. We want to continue anyway end catch select 1 --do something else IF (XACT_STATE()) = -1 rollback tran IF (XACT_STATE()) = 1 commit tran




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签