-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL Server transaction support #28
Comments
Here is another hacky way to do it probably - you'll have to add the check if it is indeed a SqlConnection first though of course: private static readonly PropertyInfo ConnectionInfo = typeof(SqlConnection).GetProperty("InnerConnection", BindingFlags.NonPublic | BindingFlags.Instance); Alternatively you could always use a transaction, with the setting to join an existing transaction if available. |
@niwrA : Bit confused by the first part of your comments! You seem to have just retyped the same solution from the same source that I linked to in the original post?! You're right that it does need to be a Possibly what you suggest last might work, except that in the case of Mighty (at least) it is much better if user code outside of Mighty manages any transactions, because Mighty (following Massive) uses delayed execution a lot. So any transactions Mighty opens, it has to close, but only later when the user has enumerated through any enumerables. That probably isn't a good way to design things, because that would be complex to get right (given this architecture) and likely leave dangling transactions without the user understanding why. |
The idea of Mighty transaction support is that you can optionally pass a
DbConnection
into all Mighty methods, and thus that you can get Mighty methods to automatically work with any transactions which are open on the connection.Unfortunately SQL Server doesn't work like that! (All other ADO.Net SQL drivers which Mighty supports do.) In SQL Server you have to manually join a
DbCommand
to a transaction even if the command is operating on a connection which has a transaction open.There is also no clean, official way to automatically join a
DbCommand
to the open transaction on a connection.Fortunately, there is a slightly 'hacky' way to do it, which works and seems to have remained stable for a while, although it is NOT officially supported. As this makes transactions very much easier to work with in SQL Server in Mighty, I have added this code to Mighty and enabled it by default.
SqlServerAutoEnlistCommandsToTransactions
DbConnection
with the open transaction to the Mighty commandMighty.CreateCommand
, then join the command to the transaction yourself, and then use one of the Mighty variants which takes aDbCommand
to execute it; i.e. it's possible, but much more fiddly, without this supportThe text was updated successfully, but these errors were encountered: