在事务中启动新流程
我必须在第三方应用程序中创建一个用户,并将其信息存储在 SQL Server 中,并且我还将有关该用户的信息存储在我们的应用程序数据库(也在 SQL Server 中)中。
我希望将这两个更新包装在 TransactionScope 中,以便它们可以一起成功或回滚。 不幸的是,我创建用户的唯一方法是通过命令行实用程序,我当前正在通过 Process.Start 调用运行该实用程序。 我希望新进程仍会加入我的活动事务中,但情况似乎并非如此。
碰巧,两个数据库位于同一台服务器计算机上,但位于不同的实例下。 我的应用程序是用 C# 为 .NET 3.5 编写的,
我是否做错了什么,或者是否有某种明确的方法可以让此进程加入事务,或者我只需手动回滚更改?
I have to create a user in a third party application that stores its information in SQL Server, and I also store information about this user in our application database, also in SQL Server.
I was hoping to wrap both updates in a TransactionScope, so they can succeed or rollback together. Unfortunately the only method I have for creating users is via a command-line utility, that I am currently running through a Process.Start call. I was hoping the new process might still enlist in my active transaction, but this does not seem to be the case.
As it happens, both datbases are on the same server machine, but are under different instances. My application is written in C# for .NET 3.5
Am I doing something wrong, or is there some explicit way to get this process to enlist in the transaction, or will I just have to manually rollback the changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在分布式事务中加入命令行应用程序 - 不认为这是可以做到的。
Enlist command line app in distributed transaction - don't think this can be done.
回答你的问题:它们不能自动进入相同的事务范围。 尝试先创建用户,这样,如果失败,您甚至不会在数据库中创建记录。
如果用于创建用户的命令行进程返回错误代码(“public static int Main()”中的 int 进行检查,并将其作为交易结果的一部分。0 表示成功,其他通常表示 。
如果它没有创建错误代码,但在 STDERR 上创建一些文本,则覆盖 STDERR 流,读取它的输出并以这种方式进行检查
To answer your question: They can't automatically go into the same transaction scope. Try to create the user first, that way, if it fails you don't even create the records in your db.
If your Command Line process that you use to create the user returns an error code, (the int in 'public static int Main()' check that and make that part of the result of your transaction. 0 means success, everything else usually means failure.
If it doesn't create an error code. but some text on STDERR, override the STDERR stream, read it's output and check that way.