SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Procedure stops in .NET application
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

martind1
Starting Member

United Kingdom
28 Posts

Posted - 08/10/2012 :  03:59:52  Show Profile  Reply with Quote
Hi,

I have got a procedure setup and when I call it from SQL managerment studio, it runs absolutely fine in under 2 seconds.
The procedure performs lots of updates on a table, runs fine in Management studio.

However, when its called from a .NET application, it just hangs for over 6 hours, and never completes.
The procedure has no parameters.
I have tried adding WITH RECOMPILE to the procedure but had no effect.

I have looked into the running query stats and it isn't making any more reads or writes after a certain amount of time.
I have also looked into sp_who2 and it has 2 UPDATE commands marked as RUNNABLE and 3 marked as SUSPENDED.

Its really got me stumped.
Any suggestions?

--
http://www.tutorial-resource.com - Free Web Development Resources

Edited by - martind1 on 08/10/2012 04:04:42

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3438 Posts

Posted - 08/10/2012 :  05:01:15  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
best advice is to fire up sql serverprofiler on the sql server then run the application version of the update.

http://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&sqi=2&ved=0CCEQFjAA&url=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms181091.aspx&ei=ys0kUKiDJInT0QWSq4DICg&usg=AFQjCNHqAcM2nSfDP81KaUhYDgeRk6pfDA

You'll see exactly what is issued to the db.

My guess is that you have contention / blocking caused by some connection. Possibly you are trying to read from and update the table(s) at the same time.

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

martind1
Starting Member

United Kingdom
28 Posts

Posted - 08/10/2012 :  05:08:36  Show Profile  Reply with Quote
I will take a look at the trace now and let you know my results :)

--
http://www.tutorial-resource.com - Free Web Development Resources
Go to Top of Page

martind1
Starting Member

United Kingdom
28 Posts

Posted - 08/10/2012 :  07:35:55  Show Profile  Reply with Quote
Trace revealed no results to the problem.
Going to try it on another server see if it works then.

--
http://www.tutorial-resource.com - Free Web Development Resources
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3438 Posts

Posted - 08/10/2012 :  08:48:50  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
if it's hanging and not doing anything there will be something happening....

You could trigger the change (via application)

and then in management studio run

EXEC sp_who2

and look for blocking jobs?

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

martind1
Starting Member

United Kingdom
28 Posts

Posted - 08/10/2012 :  09:02:45  Show Profile  Reply with Quote
Ive ran sp_who2 while the procedure runs or hangs, and there is no blocking queries. Its just very odd.

--
http://www.tutorial-resource.com - Free Web Development Resources
Go to Top of Page

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 08/10/2012 :  13:18:55  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
post the .net code from connection string onward

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

martind1
Starting Member

United Kingdom
28 Posts

Posted - 08/11/2012 :  03:08:24  Show Profile  Reply with Quote
Here is my c# code. All other procedures called from the application use exactly the same code, just a different procedure name.

string connectionString = ConfigurationManager.AppSettings["DatabaseCS"].ToString();

SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand sqlCommand = new SqlCommand("DisableDuplicatePackages", sqlConnection);
sqlCommand.CommandTimeout = 0;
sqlCommand.CommandType = CommandType.StoredProcedure;

try
{
	sqlConnection.Open();
	
	sqlCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
	Exceptions.LogException(ex);
}
finally
{
	sqlConnection.Close();
}


--
http://www.tutorial-resource.com - Free Web Development Resources
Go to Top of Page

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 08/14/2012 :  12:18:14  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
if they all use the same c# call then the issue is most definitely in your sproc. if you are able to post that or show us the pseudocode for it

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

martind1
Starting Member

United Kingdom
28 Posts

Posted - 08/15/2012 :  05:01:13  Show Profile  Reply with Quote
Hi,

I have solved the issue by re-writing the stored procedure to do it a different way. It was updating a table and doing a select at the same time. Now I'm just grouping to get a unique id instead. Still doesn't explain why it worked in management studio and not in the .net application.

Anyway, problem solved, kind of lol :)

Cheers

--
http://www.tutorial-resource.com - Free Web Development Resources
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000