解决MSSQL下“不能在手动或分布事务方式下创建新的连接”的问题

作者:Juven 来源:织梦幻影 时间:2008-07-15 12:48:00 

相信在使用MSSQL数据库下使用事务回滚方式操作多表记录的时候,会经常出现“不能在手动或分布事务方式下创建新的连接”的出错提示信息,这个问题也已困扰我多年。

这次在开发一个大型的商务平台的时候,涉及到数据的计算,同时也必须要多表更新(或删除)。借助GOOGLE也没找到一个真能解决的问题。以前收集过一个MSDN的说明,官方的提示必须,只有用SQL语句执行数据库操作才能使用事务处理

  从官方提示上理解,事式处理中涉及到查询(Select)时,会出现这种出错提示。同时也应该与记录指针(Cursors)有关联。试着这样的思路,将事务处理中原出现的Conn.Execute("select ... from ...")修改为使用rs.Open...命令打开记录集,问题解决。

  解决的方法只涉及到Juven的理解,并无权威确认!

  MSDN说明:

Tips for Working with Cursors 
Some providers, such as SQL Server, implement a forward-scrolling, read-only (or 'firehose') cursor mode, meaning that they can efficiently retrieve data by keeping a connection open. When working with such providers, the connection could be blocked by another user's transaction. The following examples demonstrate scenarios 
that result in errors. 
dbConn.Open "DSN=SQLForum;UID=sa;PWD=;" 
'Example 1 
dbConn.BeginTrans 
RS.Open "Select * FROM Message", dbConn 
Set dbCmd.ActiveConnection = dbConn
Example 1: The problem is that the command object's ActiveConnection is being set to a connection that is forward-scrolling and in 'firehose' mode. This is the same connection involved in the batch mode. The error from the provider will only appear in the Err object, and it will return as unspecified. For example, with the ODBC 
Provider, you will get "Unspecified error". 

dbConn.Open "DSN=SQLForum;UID=sa;PWD=;" 
'Example 2 
RS.Open "Select * FROM Message", dbConn 
dbConn.BeginTrans 
Example 2: The problem here is that the connection is forward-scrolling and in firehose mode, so it cannot be put into transaction mode. The error returned in the Errors collection from the provider will indicate that it is operating in firehose mode, and can't work in transaction mode. For example, with the ODBC Provider against 
Microsoft SQL Server, you will get the error "Cannot start transaction while in firehose mode". 

dbConn.Open "DSN=SQLForum;UID=sa;PWD=;" 
'Example 3 
RS.Open "Select * FROM Message", dbConn 
Set dbCmd.ActiveConnection = dbConn 
dbConn.BeginTrans 
Example 3: The problem here is that the connection is in forward-scrolling firehose mode, so it cannot also be involved in a batch mode. The error returned in the Errors collection from the provider will indicate that the transaction could not be started. For example, with the ODBC Provider against Microsoft SQL Server, you will get the error "Cannot start transaction because more than one hdbc is in use". 
标签:mssql,错误,sql
0
投稿

猜你喜欢

  • 记录下两个正则表达式的使用

    2009-11-30 12:56:00
  • IE8网页显示不正常 用”兼容性视图”搞定

    2009-03-28 11:13:00
  • INPUT的对齐问题

    2008-05-24 08:32:00
  • 又为ajax上传工具重新写了一个服务器端上传程序

    2009-12-21 14:30:00
  • focus 进 textarea 元素后光标位置的修复

    2008-09-27 13:27:00
  • asp上传文件自动重命名方法

    2007-08-24 09:46:00
  • ASP小偷(远程数据获取)程序的入门教程

    2007-09-21 12:48:00
  • Oracle数据库密码文件的使用与维护

    2010-07-28 13:27:00
  • 【JavaScript实用系列】-- 胖页面载入效果

    2009-10-19 22:48:00
  • taobao cdn的缓存?

    2009-09-19 17:21:00
  • 10个提高网站可用性的实用技巧[译]

    2009-06-12 12:37:00
  • 怎么让别人看不到网页源代码

    2008-03-21 13:06:00
  • Oracle 触发器的使用小结

    2009-05-24 19:54:00
  • 浅谈javascript的分号[译]

    2009-12-13 10:34:00
  • 如何在ADO服务器端利用好缓存技术?

    2010-06-17 12:49:00
  • 如何编写一个过滤掉HTML代码的函数?

    2009-11-08 18:53:00
  • asp组件上传

    2010-05-27 12:16:00
  • 精细分析 SQL server服务器的内存配置

    2009-01-19 13:56:00
  • SQL Server中索引使用及维护

    2008-11-25 11:13:00
  • MYSQL server has gone away解决办法

    2010-11-25 17:22:00
  • asp之家 网络编程 m.aspxhome.com