Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Converting ASP.Net to .Net 4.0 throws MSDTC error
Old 12-08-2011, 01:04 PM Converting ASP.Net to .Net 4.0 throws MSDTC error
Novice Talker

Posts: 6
Name: Melanie Peterson
Trades: 0
Hi - I've just converted an ASP.Net 2.0 solution to 4.0. In general, it seems to work fine, but there's one point in the code that consistently throws an error on 2 Windows 7 machines, one 32-bit, one 64-bit. The same code works fine on a Windows 2003 machine in the 2.0 framework. Note that both versions are being run through Visual Studio, the 2.0 version in VS2005, the 4.0 version in VS2010. I also get the same error message if I publish the 4.0 version to a Windows 7 machine and run it from IIS or in the browser (IE9). The code that breaks is as follows:
Code:
 
string strSelect = "SELECT * FROM Tasks WHERE UserID = " + UserID + " AND ClsdDate IS NULL AND Task LIKE 'Employee Move - " + RequestItemName + "%'"; 
SqlConnection dsConn = new SqlConnection(ConfigurationManager.AppSettings["DSN_TRACKIT"].ToString());
SqlDataAdapter dsDataAdapter = new SqlDataAdapter(strSelect, dsConn);
SqlCommandBuilder dsCommandBuilder = new SqlCommandBuilder(dsDataAdapter);
dsDataAdapter.UpdateCommand = dsCommandBuilder.GetUpdateCommand();
dsDataAdapter.Fill(dsTrackit,"MoveTasks");
The error message is:

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 Administrative tool

Note that the code does not involve a transaction, or more than one SQL Server and my DBA swears that DTC is enabled on ALL SQL Servers involved in this solution.

So what's going on here? I've googled the error message, but I've seen nothing that could explain this. I don't know if this is a Windows 7 issue or a .Net 4.0 issue.

Thanks!
mellomel70 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-08-2011, 02:34 PM Re: Converting ASP.Net to .Net 4.0 throws MSDTC error
chrishirst's Avatar
Defies a Status

Posts: 43,963
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Print the query to the browser to ensure all the values are within appropriate ranges
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-09-2011, 10:20 AM Re: Converting ASP.Net to .Net 4.0 throws MSDTC error
Novice Talker

Posts: 6
Name: Melanie Peterson
Trades: 0
The query runs fine in Management Studio. It returns 0 rows, which should not be a problem.
mellomel70 is offline
Reply With Quote
View Public Profile
 
Old 12-13-2011, 11:05 AM Re: Converting ASP.Net to .Net 4.0 throws MSDTC error
Extreme Talker

Posts: 246
Trades: 0
On each of the machines that you have this running, where is this pointing to: ConfigurationManager.AppSettings["DSN_TRACKIT"].ToString()
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 12-13-2011, 12:37 PM Re: Converting ASP.Net to .Net 4.0 throws MSDTC error
Novice Talker

Posts: 6
Name: Melanie Peterson
Trades: 0
ConfigurationManager.AppSettings["DSN_TRACKIT"].ToString() is a key like this:

<addkey="DSN_TRACKIT"value="server=MYSERVER\MYINSTANCE; uid=sa; pwd=mypassword; database=MYDATABASE;"/>



I've been trying to post a reply to this thread for two days; there must be something in my reply that's causing IE to explode. So I'm going to try to post an overview of what I've tried without posting explicit code. I appreciate your patience.

In order to solve my problem, I set a string variable to be my SELECT statement, where the SELECT statement does a SELECT COUNT(*) and evoked it with ExecuteScalar.
This errors out with the same error message when I try to open my connection.
I dug farther into the code and realized that this SELECT statement is inside a transaction that's opened two levels up. Within the transaction there are calls to another database server, so I'm guessing that that's where the DTC error is coming from.
Basically, within the transaction (which is set to IsolationLevel ReadCommitted), there are two calls to a SQL Server 2008 R2 server which work fine. Then comes a method that calls a method that calls my SELECT statement to a SQL Server 2003 server.
Note that this code works fine in .Net 2.0, but breaks if I convert the solution to 4.0. It also breaks if I convert the solution to 3.5. Could the problem be the IsolationLevel setting? I can't imagine why that would be the case, but....
I did manage to get around this problem by creating a stored procedure to do the SELECT statement and calling it through a linked server on the 2008 R2 machine.
HOWEVER, when the next ADO.Net call is made to the 2008 R2 machine, I get "Error Message: The operation is not valid for the state of the transaction."
I'm stumped. Any ideas?
mellomel70 is offline
Reply With Quote
View Public Profile
 
Old 12-14-2011, 11:19 AM Re: Converting ASP.Net to .Net 4.0 throws MSDTC error
Novice Talker

Posts: 6
Name: Melanie Peterson
Trades: 0
Just want to clarify that I'm only an idiot occasionally. I meant to say SQL Server 2005 server, not 2003....
mellomel70 is offline
Reply With Quote
View Public Profile
 
Old 12-14-2011, 02:36 PM Re: Converting ASP.Net to .Net 4.0 throws MSDTC error
Novice Talker

Posts: 6
Name: Melanie Peterson
Trades: 0
I figured this out and it's so simple I want to shoot myself. But I won't; no need to dial 911. I'm calling my code on a new Windows 7 machine. To check if MSDTC was enabled for this machine, I went to Administrative Tools -> Component Services -> Computers -> My Computer and right-clicked for Properties. All I saw was a screen telling me that "use local coordinator" was enabled. Okay, I thought, it looks different from the SQL Server settings because it's a client. BUT - I discovered today that there's a whole host of other MSDTC settings on my machine. You get to them by going to Administrative Tools -> Component Services -> Computers -> My Computer -> Distributed Transactions -> Local DTC and right clicking for Properties. Sure enough, my machine wasn't set to allow DTC. Once I changed this, every works fine (well, now I've got another issue, but so what else is new?). I'd probably read this a million times on different websites and it just hadn't taken.
mellomel70 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Converting ASP.Net to .Net 4.0 throws MSDTC error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.42268 seconds with 11 queries