sqltransaction [英] sqltransaction
问题描述
大家好,
我正在asp.net2.0网页中使用事务.
我可以使用单独的sqlstatement在tran.open和trans.commit之间获取某些值,而不是事务语句.
我在asp.net 1.1中使用了相同的东西,并且运行良好.
但是在2.0中,它给出了一个错误消息,指出此交易已完成",并且不再可用.
例如:
Hai all,
I am using transaction in my asp.net2.0 web page.
Can I use a seperate sqlstatement to fetch some value in between tran.open and trans.commit other than transaction statements.
I have used samething in asp.net 1.1 and it is working perfectly.
But in 2.0 it is giving an error saying "this transaction is completed" and it is no more usable.
Ex:
sqlconn.Open()
Try
myTrans = sqlconn.BeginTransaction()
s1.Connection = sqlconn
s1.Transaction = myTrans
s1.CommandText ="insert statement"
s1.ExecuteNonQuery()
在这里,我想使用一条select语句,该语句通过打开和关闭db连接从updateba中使用的databae中获取一些值.
这种现象在.net 1.1中起作用,并在.net 2.0中给出上述错误
Here i wanted to use a select statement which will fetch some value from databae which am using in my update statement by opening and closing a db connection.
this phenomena is working in .net 1.1 and giving the said error in .net 2.0
s1.CommandText ="some update statement"
s1.ExecuteNonQuery()
myTrans.Commit()
Catch ex As Exception
myTrans.Rollback()
mb.ShowMessagebox(Page, ex.Message)
Finally
sqlconn.Close()
end try
如果有人知道解决方案,请告诉我.
在此先感谢
if somebody knows the solution please let me know.
thanks in advance
推荐答案
我可以考虑的可能原因是
在.Net 2.0中,如果要为一个连接执行多个语句,则需要打开MARS功能(您需要在连接字符串中打开此功能,默认情况下处于关闭状态).
如果第一条语句容易出错,您将遇到上述错误.例如,它可能排除了某些在插入过程中的数据库约束等.
希望对您有所帮助!.
问候,
-Vinayak
Hi,
Probable reasons which i can think off are,
In .Net 2.0, If you want to execute more than one statement for one connection , you need to switch on the MARS feature(You need to turn on this feature in connection string, by default this is off).
The above mentioned error you will get if the first statement turns out to be error prone....for instance it could be ruling out some of the data base constraints during its insertion etc..
I hope this helps!.
Regards,
-Vinayak
如果要在ASP.NET页中而不是在数据层dll中编写SQL,则说明您的设计已经损坏.但是,您的问题尚不清楚.您不能在一个事务中运行多个命令?如果仅将所有SQL捆绑到一个命令中并运行该命令怎么办?我希望您不是将字符串SQL混在一起吗?为什么您不使用存储的proc?
If you''re writing SQL in your ASP.NET pages, and not in a datalayer dll, then your design is already broken. However, your question is far from clear. You can''t run more than one command in a transaction ? What if you just bunch all your SQL in to one command and run it ? I hope you''re not string mashing your SQL together ? Why are you not using stored procs ?
我认为您可以使用收集数据集"中的所有想要的值并在事务之间将其用作脱机而不是实时使用来做到这一点. />
谢谢
Hiren Solanki
I think you can do that with Gather all the values which you want in Dataset and Use it in between transaction as a offline rather then live.
Thanks
Hiren Solanki
这篇关于sqltransaction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!