 |
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
 | This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

April 4th, 2009, 01:45 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
|
|
Problem Saving New Users
I'm really enjoying this book, and it has been an immense help in a project I'm doing at work.
So far most of the code I have is straight from the book, with the exception of namespaces and the name of the DataContext, and I'm encountering an error that I've not been able to resolve today when trying to save a new user.
When the program hits the IsDuplicate method, the var result = db.ExecuteQuery<DuplicateCheck>(sql, new object[] { value, id }); line causes the following error:
"TransactionManagerCommunicationException was unhandled by user code"
"Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administration Tool."
I commented out the offending line and returned false, but I got the same error when the db.Insert() method was called.
I've done some research, and seen a number of posts that it may be a Full Trust issue? I've also seen some posts that indicate multiple transactions can trigger the MSDTC, but since all the instances of the DataContext are in using blocks, I don't think that would be it?
I'm running on a local host on Windows XP, against a Sql Server 2005 instance on a different server using VS 2008 (no SP1 though). There's no problem reading from the database, and the login created for the app has dbo_owner and public database role membership.
Any ideas on where to look or what to do would be appreciated. Thanks :)
Tim
|
|

April 4th, 2009, 09:51 AM
|
|
Wrox Author
|
|
Join Date: Jan 2009
Posts: 73
Thanks: 0
Thanked 7 Times in 7 Posts
|
|
Make sure that when you call the IsDuplicate method you are using the same DataContext when you started the transaction. The Save method begins the transaction and then creates an instance of the DataContext object. This is then passed to the Validate method. If the Validate method makes any calls to the DAL be sure to pass the existing DataContext object to the DAL methods.
Let me know if this works.
Vince
|
|

April 5th, 2009, 01:59 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
|
|
Hi Vince -
Thank you for your reply. I stepped through the code and made sure that I only had one DataContext instantiated. I did, and kept getting the same error.
The inner exception error was The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024), so on a semi-educated guess (read whim) I commented out the TransactionScope.
Voila! It worked (well, there were a couple more things to fix but that was due to my fumble fingers).
I'll toss a wad of paper over my cube wall Monday AM at our DBA to see if there's some magic he can work for me (assuming we don't have a coporate policy that prevents it). I had thought about not using transactions, but I'd really like to have that capability when updating multiple and/or related records (the ultimate destination database files are DBF format, but the framework will run in SQL as per your work, and everything I'm doing except the very last part will be in SQL, and all of our audit trails will be there as well).
Thanks again for both your book and your help :)
Tim
|
|

April 6th, 2009, 06:31 PM
|
|
Wrox Author
|
|
Join Date: Jan 2009
Posts: 73
Thanks: 0
Thanked 7 Times in 7 Posts
|
|
Send me the code and I can take a look for you. My email address is [email protected]
|
|

April 7th, 2009, 02:39 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Tim,
I'm getting the same error: InnerException = "The current TransactionScope is already complete" Can you explain how you fixed your problerm. One thing I did notice is that if I close Visual Studio and re-open the problem does not occur, but the record is not saved. I get the new ID back I can see it running through sql profiler, but no record. When you run the code a second time, then you get this error.
Thanks,
-realkewl
|
|

April 9th, 2009, 01:56 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
|
|
Hi Vince -
I'll send the code tomorrow when I'm back at work. It should be the same code as in your book (except for the DataContext name and the namespaces), but it's possible I fumble-fingered something. Thanks.
Tim
|
|

April 9th, 2009, 02:04 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
|
|
Hi realkewl -
I haven't got it to work yet, though our DBA did enable the MSDTC on the SQL Server. To get around the problem (temporarily, so as to not stall my development work) I simply commented out the using statement.
It looks like your error is different than mine. Without seeing your code, it's hard to say what's going on (and I'm not strong in SQL transactions to start with). You might want to double-check where you're starting and committing the transactions.
As a guess, based on the described behavior, it sounds like maybe the insert is working but the transaction is not getting committed (hence getting an ID back), and when you re-run the insert the program tries to reuse the previous connection?
Like I said, transactions aren't my strong suit and I'm basically whistling in the dark here (and running on way too little sleep).
Here's a link that might give you some things to look at:
http://social.msdn.microsoft.com/for...-079d5fd6e519/
Tim
|
|

April 9th, 2009, 11:12 AM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hi TIm,
Thanks for the replay. Well, actually my error, I think is that the transaction is being committed before I call the TransactionScope.Complete(), so I get the error message saying the transaction is already complete...weird. So when I comment out the transaction stuff...my code works just fine. I can add and update an existing record. Which is fine for me because I think I will wrap my transaction inside sql server.
But here's the code ( VB) from ENTbaseEO for save that I commented out the TransactionScope:
Code:
PublicFunction Save(ByRef validationErrors As ENTValidationErrors, ByVal userAccountId AsInteger) AsBoolean
Dim ts As TransactionScope = Nothing
Dim db AsNew HRPaidTimeOffDataContext
If gDBAction = DBActionEnum.Save Then
'ts = New TransactionScope --- commented out
If Save(db, validationErrors, userAccountId) Then
'ts.Complete() - this was causing my error -- commented out
ReturnTrue
Else
ReturnFalse
EndIf
Else
ThrowNew Exception("DBAction not Save.")
EndIf
EndFunction
Hope you got some sleep... :-)
Thanks,
-realkewl
|
|

April 9th, 2009, 04:05 PM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
|
|
Hmmm....two things to check.
First, you have:
ts = New TransactionScope - you're missing the () at the end of the call to the constructor (don't know if this matters or not).
Second, although a quick check of google didn't provide confirmation, I'm pretty sure that the Transaction Scope needs to be in a Using block. Try this:
If gDBAction = DBActionEnum.Save Then
Using ts As New TransactionScope()
If Save(db, validationErrors, userAccountId) Then
ts.Complete();
Return True;
Else
Return False;
End If
End Using
Else
Throw New Exception("DBAction not Save.")
End If
Get rid of the Dim ts As TransactionScope line at the beginning of the function. Also, where is your instantiation of HRPaidTimeOffContext (or did you leave it out of the paste for brevity)?
Hope this helps.
And yes, I got some sleep, but it's never enough :)
Tim
|
|

April 9th, 2009, 04:54 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks Tim, I'll do more research and see what I come up with. Will keep you posted if I find a solution.
-realkewl
|
|
 |