如何使用经典ASP设置事务隔离级别?

时间:2015-06-25 12:53:22

标签: sql-server tsql asp-classic isolation-level

我有一个classic ASP页面,想要将transaction isolation level设置为READ UNCOMMITTED。使用this documentation我提出了以下内容:

Set conn = GetConnection
conn.IsolationLevel = adXactReadUncommitted

'conn.BeginTrans

'conn.CommitTrans

Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = conn

cmd.CommandType = adCmdText
cmd.CommandText = "INSERT INTO [dbo].[A] ([IsolationLevel]) SELECT CASE transaction_isolation_level  WHEN 0 THEN 'Unspecified'  WHEN 1 THEN 'ReadUncommitted'  WHEN 2 THEN 'ReadCommitted'  WHEN 3 THEN 'Repeatable'  WHEN 4 THEN 'Serializable'  WHEN 5 THEN 'Snapshot' END AS TRANSACTION_ISOLATION_LEVEL  FROM sys.dm_exec_sessions  where session_id = @@SPID"
Set rs = cmd.Execute()

response.write(conn.IsolationLevel)

最后一次response.write正确地给了我256READ UNCOMMITTED),但当我查询表格时,我只获得了ReadCommitted条记录。

有谁能说出我做错了什么?

这是GetConnection函数的主体:

FUNCTION GetConnection()
    DIM strConnectionDotNet : strConnectionDotNet = "Data Source=..."
    SET GetConnection = Server.CreateObject("adodb.connection")
    GetConnection.connectionstring="Provider=sqloledb;" & strConnectionDotNet
    GetConnection.open
END FUNCTION

1 个答案:

答案 0 :(得分:2)

正如文件中所述:

  

注意:IsolationLevel设置在下次之前无法使用   调用BeginTrans。

这有点奇怪,但我需要以下内容:

conn.BeginTrans
... sql statement is executed here
conn.CommitTrans

甚至认为T-SQL语句是SELECT。此外,在conn.CommitTrans之后它仍然使用默认隔离级别(在数据库上下文中指定的级别)。