Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 4th, 2009, 02:45 AM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default 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
  #2 (permalink)  
Old April 4th, 2009, 10:51 AM
Wrox Author
 
Join Date: Jan 2009
Posts: 73
Thanks: 0
Thanked 7 Times in 7 Posts
Default

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
  #3 (permalink)  
Old April 5th, 2009, 02:59 AM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default

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
  #4 (permalink)  
Old April 6th, 2009, 07:31 PM
Wrox Author
 
Join Date: Jan 2009
Posts: 73
Thanks: 0
Thanked 7 Times in 7 Posts
Default

Send me the code and I can take a look for you. My email address is vince.varallo@poweredbyv2.com
  #5 (permalink)  
Old April 7th, 2009, 03:39 PM
Authorized User
 
Join Date: Mar 2009
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
  #6 (permalink)  
Old April 9th, 2009, 02:56 AM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default

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
  #7 (permalink)  
Old April 9th, 2009, 03:04 AM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default

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
  #8 (permalink)  
Old April 9th, 2009, 12:12 PM
Authorized User
 
Join Date: Mar 2009
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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
  #9 (permalink)  
Old April 9th, 2009, 05:05 PM
Authorized User
 
Join Date: Apr 2009
Posts: 41
Thanks: 1
Thanked 2 Times in 2 Posts
Default

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
  #10 (permalink)  
Old April 9th, 2009, 05:54 PM
Authorized User
 
Join Date: Mar 2009
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Tim, I'll do more research and see what I come up with. Will keep you posted if I find a solution.

-realkewl
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
users login problem luisman_luisman BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 8 November 12th, 2009 03:48 PM
Problem with users seeing each other's data gp_mk ASP.NET 1.0 and 1.1 Professional 11 October 2nd, 2006 08:39 AM
Problem with authentication users hcusto BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 9th, 2006 03:32 PM
saving shopping cart on users computer... elladi Classic ASP Basics 1 November 17th, 2004 10:03 PM



All times are GMT -4. The time now is 06:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.