程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MSSQL數據庫不能手動創建新的連接

MSSQL數據庫不能手動創建新的連接

編輯:MySQL綜合教程

相信在使用MSSQL數據庫下使用事務回滾方式操作多表記錄的時候,會經常出現“不能在手動或分布事務方式下創建新的連接”的出錯提示信息,這個問題也已困擾我多年。

  這次在開發一個大型的商務平台的時候,涉及到數據的計算,同時也必須要多表更新(或刪除)。借助GOOGLE也沒找到一個真能解決的問題。以前收集過一個MSDN的說明,官方的提示必須,只有用SQL語句執行數據庫操作才能使用事務處理

  從官方提示上理解,事式處理中涉及到查詢(Select)時,會出現這種出錯提示。同時也應該與記錄指針(Cursors)有關聯。試著這樣的思路,將事務處理中原出現的Conn.Execute("select ... from ...")修改為使用rs.Open...命令打開記錄集,問題解決。

   以下為引用的內容:
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".

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved