|
hello
I ran into this error message while before/while/after insert into ShopMessage...
<br />
Message "Cannot access a disposed object.\r\nObject name: 'Transaction'." string<br />
I'm using TransactionScope with timeout set to zero (i.e. infinite). Googled a bit still quite clueless.
This is how I wrap Database calls in TransactionScope
<br />
<br />
using (oScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMilliseconds(0)))<br />
{<br />
nGeneratedId = SaveCoreOperations(ref oShop);<br />
oScope.Complete();<br />
}<br />
Here's the stack trace
<br />
at System.Transactions.Transaction.get_IsolationLevel()<br />
at System.Data.SqlClient.SqlDelegatedTransaction..ctor(SqlInternalConnection connection, Transaction tx)<br />
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)<br />
at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)<br />
at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)<br />
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)<br />
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br />
at System.Data.SqlClient.SqlConnection.Open()<br />
at NHibernate.Connection.DriverConnectionProvider.GetConnection()<br />
at NHibernate.Impl.SessionFactoryImpl.OpenConnection()<br />
Any idea?
dev
|
|
|
|
|
devvvy wrote: SaveCoreOperations(ref oShop);
I don't think you need a ref here.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
yes you're right about not needing the ref, but that's not what i am asking either.
I am suspecting TransactionScope called Transaction.Dispose somehow.
dev
|
|
|
|
|
devvvy wrote: using (oScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMilliseconds(0)))
{
// Here we have some ADO.NET calls + some NHibernate calls.
nGeneratedId = SaveCoreOperations(ref oShop);
oScope.Complete();
}
Where is oScope used?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
some inside SaveCoreOperation and hint, death came after many iterations
dev
|
|
|
|
|
But you never passed oScope to this method. It takes the only parameter which is oShop
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
why'd you need to, scope wraps code whether inline or not between "using" open and close bracket.
using (oScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMilliseconds(0)))<br />
{<br />
nGeneratedId = SaveCoreOperations(oShop);
oScope.Complete();<br />
}
I am suspecting perhaps from within "SaveCoreOperations" oConn used was opened/closed then "Re-opened"... not sure
dev
|
|
|
|
|
You can get this error message if your Distributed Transaction Coordinator service is not running. Use Administrative Tools to check the Status of the service has Started and that the Startup Type is Automatic.
Also, the default timeout/timespan is 1 minute and the default machine config caps it to 10 minutes.
modified on Wednesday, August 26, 2009 11:14 PM
|
|
|
|
|
Hi
Im placing some controls dynamically on tool strip control and i'm handling that controls click event as well tool strips click event. But when ever i click the control it triggers both the event.
I want to cancel tool strips event when i click the control.. how can i do this?
|
|
|
|
|
Do you need the toolstrip's Click event to be handled at all (I've never found a need for it personally as all I'm ever interested in is the items, not the strip)?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Well, I'm handling tool strip click event also with different context.
|
|
|
|
|
|
What is it that you are using the ToolStrip's click event for?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi,
Do you have any idea on how to attache image/docs/pdf saved from SQL DB then send it to email?
All the attachements of diff. docs are all saved in our SQL DB, they want me to send the attched files as per record at attachment to email.
PLSzzz.
Dabsukol
|
|
|
|
|
Have a look at this[^]
The example is in VB.Net but I hope you can easily convert it to C#.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
form name is "Test".
i want to close this form using short cut Alt+F4
cany anyone help me
|
|
|
|
|
Normally this should work by default...
|
|
|
|
|
Just press Alt+F4 in your keyboard. The form will be closed automatically.
You don't need to write some codes for that.
|
|
|
|
|
It should just work as others have said. If for some reason it doesn't, you can code it yourself. This is a little function I use occaisionally to do the opposite - stop Alt+F4 closing the form. Adapt it to suit.
private const int WM_SYSKEYDOWN = 0x0104;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
return ((msg.Msg == WM_SYSKEYDOWN) && (keyData == (Keys.Alt | Keys.F4)));
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
try
{
int i = 1;
int j = 2;
return i;
}
finally
{
i += 3;
}
The code in the finally statement will be executed ? when? before return or after return ?
|
|
|
|
|
What happened when you tried?
|
|
|
|
|
Well, that's a dumb question. If there's no other code, then before or after the return are basically the same thing, excepting that when the code returns, i will no longer exist. In fact, I don't think this will compile, because the scope of i is the try block, I think you need to define it outside the try for the catch to see it.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Well that is a dumb answer because it's totally unhelpful!
You're right that it won't compile, but surely you can see that the question works by simply declaring i at the method level instead. And there is in fact a subtle effect of the try-finally.
int foo()
{
int i = 1;
try { return i; }
finally { i = 5; }
}
This code compiles, but what does foo() return? I think quite a lot of people would expect it to return 5, since the finally block is executed before the method returns. But the return value is *evaluated* before the finally block runs and the method returns 1.
Now what would happen if we boxed the int in a class of our own?
class BoxedInt { public int Value; }
BoxedInt bar()
{
BoxedInt i = new BoxedInt() { Value = 1 };
try { return i; }
finally { i.Value = 5; }
}
While foo() returns 1, bar() returns a BoxedInt whose Value is 5. That's because BoxedInt is a class and thus a reference type, so it does not matter if the return value is evaluated before or after the finally block executes. Change BoxedInt to a struct, and bar will return a BoxedInt with Value equal to 1 as well.
I'd say there's some subtlety here, so calling that a stupid question seems to me rather a stretch.
|
|
|
|
|
So... you did try it, but asked the question anyway?
|
|
|
|
|
Now that got me nicely confused.
You replied to my message so presumably "you" means me. But what "it" and "the question" refers to is less clear. I tried many things including compiling and running the various code snippets I've put up on this thread. I may have asked questions too, but I am not the OP so if you were referring to the original message that might explain the confusion.
If you did mean I tried something (and consequently found out what it does) and still asked what it does, let me know what it was and I will attempt to communicate whatever it was I was wondering about more clearly.
|
|
|
|