在批处理开始时检测到不可提交的事务.交易已回滚.这是由在...中处理FILESTREAM请求期间发生的错误引起的. [英] An uncommittable transaction was detected at the beginning of the batch. The transaction was rolled back. This was caused by an error that occurred during the processing of a FILESTREAM request in...

查看:335
本文介绍了在批处理开始时检测到不可提交的事务.交易已回滚.这是由在...中处理FILESTREAM请求期间发生的错误引起的.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SqlFileStream将文档保存到我的sql数据库中.数据库文件流设置似乎工作正常,当我运行查询以添加文档时,似乎正在保存它,但是当我尝试通过vb.net保存文档时,我得到此错误

在批处理开始时检测到不可提交的事务.该事务已回滚.这是由于在此事务的上下文中处理FILESTREAM请求期间发生的错误引起的."

这是我的vb.net代码

Hi, i''m trying to save documents into my sql database using SqlFileStream. the database filestream setup seems to be working ok and when i run a query on to add a document it seems to be saving it but when i try saving a document through vb.net i''m getting this error

"An uncommittable transaction was detected at the beginning of the batch. The transaction was rolled back. This was caused by an error that occurred during the processing of a FILESTREAM request in the context of this transaction."

here is my vb.net code

'Declare Database objects
           Dim SQLCon As SqlConnection
           Dim objThisTransaction As SqlTransaction
           Dim objThisCommand As New SqlCommand


           Dim strPath As String
           Dim objPatIdParam As SqlParameter
           Dim objFileTypeParam As SqlParameter
           Dim objFilePathParam As SqlParameter
           Dim objActionTakenByParam As SqlParameter

           Dim objDataAdapter As New SqlDataAdapter


           Dim buffer As Byte() = New Byte(CInt(FileUpload1.FileContent.Length) - 1) {}
           FileUpload1.FileContent.Read(buffer, 0, buffer.Length)
           If FileUpload1.FileContent.Length > 0 Then

               Dim conn As String = "Data Source=.;Initial Catalog=Review;Integrated Security=true;Trusted_Connection=Yes;"
               SQLCon = New SqlConnection(conn)
               SQLCon.Open()

               objThisTransaction = SQLCon.BeginTransaction()

               ' Specify the details of the Stored Procedure to execute
               objThisCommand = New SqlCommand("proc_Review_put_StreamFiles", SQLCon, objThisTransaction)
               objThisCommand.CommandType = CommandType.StoredProcedure

               ' Clear the parameters list
               objThisCommand.Parameters.Clear()

               objPatIdParam = objThisCommand.Parameters.Add("@PatId", SqlDbType.VarChar, 75)
               objPatIdParam.Value = Session("PatId").ToString
               objFileTypeParam = objThisCommand.Parameters.Add("@FileType", SqlDbType.VarChar, 5)
               objFileTypeParam.Value = System.IO.Path.GetExtension(FileUpload1.FileName)
               objFilePathParam = objThisCommand.Parameters.Add("@FilePath", SqlDbType.VarChar, -1)
               objFilePathParam.Direction = ParameterDirection.Output
               objActionTakenByParam = objThisCommand.Parameters.Add("@ActionTakenBy", SqlDbType.VarChar, 50)
               objActionTakenByParam.Value = Session("UserId").ToString()
               ' Now execute the stored procedure
               objThisCommand.ExecuteNonQuery()

               'file path of the document
               strPath = CStr(objFilePathParam.Value)

               objThisCommand = New SqlCommand("SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()", SQLCon, objThisTransaction)
               Dim objContext As Byte() = DirectCast(objThisCommand.ExecuteScalar(), Byte())


               Dim objSqlFileStream As New SqlFileStream(strPath, objContext, FileAccess.Write)

               objSqlFileStream.Write(Buffer, 0, Buffer.Length)
               objSqlFileStream.Close()

               objThisTransaction.Commit()
               SQLCon.Close()
               'imp.ImpersonateStop()


           End If




代码似乎在"




the code seems to fail on "

objThisTransaction.Commit()


上失败 "


"

推荐答案

您的查询是否返回大量数据? library/86773566.aspx>文章 [ ^ ]状态

当您的查询返回大量数据并调用BeginTransaction时,将引发SqlException,因为在使用MARS时SQL Server 2005不允许并行事务.为避免此问题,请始终在将事务与命令,连接或同时与二者关联之前,任何读者都是开放的."
Does your query return a large amount of data? if so this article[^] state

"When your query returns a large amount of data and calls BeginTransaction, a SqlException is thrown because SQL Server 2005 does not allow parallel transactions when using MARS. To avoid this problem, always associate a transaction with the command, the connection, or both before any readers are open."


这篇关于在批处理开始时检测到不可提交的事务.交易已回滚.这是由在...中处理FILESTREAM请求期间发生的错误引起的.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆