IT Community - Software Programming, Web Development and Technical Support

Stored procedure gets executed twice

This is a discussion on Stored procedure gets executed twice within the ASP and ASP.NET Programming forums, part of the Web Development category; Hello, I call a more complex stored procedure (sproc) from code (asp .net 2.0 website, ExecuteNonQuery()) and it always ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-30-2007, 09:13 AM
chris chris is offline
D-Web Trainee
 
Join Date: Oct 2007
Posts: 15
chris is on a distinguished road
Default Stored procedure gets executed twice

Hello,

I call a more complex stored procedure (sproc) from code (asp .net 2.0 website, ExecuteNonQuery()) and it always executes twice.
I double checked, in debugging mode, if the execute command is fired twice but it isnt.

I changed the sproc to a very simple insert statement without transactions etc. and it also gets executed twice.

If i am debugging the sproc with visual studio i can see that after the ExecuteNonQuery() it jumps into the sproc
executes it and then begins from start.

If i exec it manually via query the sproc only runs once.
I didnt post the sproc cause it doesnt matter which content it has, always the same behaviour.

If you need further information please feel free to ask.
Any hints or help would by very appreciated

I also asked the question here
http://www.discussweb.com/vb-net-pro...ted-twice.html

chris
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-31-2007, 02:11 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Stored procedure gets executed twice

can u give the code for the executing the stored procedure ....i will check that

like
SqlConnection cnPubs = new SqlConnection("server=localhost;uid=uid;pwd=pwd;Da tabase=pubs");
SqlCommand cmdAuthors = new SqlCommand("getLatLong", cnPubs);
cmdAuthors.CommandType = CommandType.StoredProcedure;
cmdAuthors.Parameters.Add("@fdate", SqlDbType.DateTime);
cmdAuthors.Parameters["@fdate"].Value = "2007-03-01 19:06:00";
cmdAuthors.Parameters.Add("@tdate", SqlDbType.DateTime);
cmdAuthors.Parameters["@tdate"].Value = "2007-03-09 14:23:00";


SqlDataReader drAuthors;
cnPubs.Open();
drAuthors = cmdAuthors.ExecuteReader();
while (drAuthors.Read())
{
Response.Write(drAuthors.GetValue(0));
Response.Write(drAuthors.GetValue(1));
}
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)

Last edited by kingmaker : 10-31-2007 at 02:28 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-31-2007, 03:49 AM
chris chris is offline
D-Web Trainee
 
Join Date: Oct 2007
Posts: 15
chris is on a distinguished road
Default Re: Stored procedure gets executed twice

I use these methods on several points the same way in my project and never had the problem with double execution of one sproc.
I also checked the beaviour with sql profiler and can see that the sproc is executed twice in short time.
This is the profiler output:
exec CheckAvailabilityAndUpdateOrderState @ord_id=68,@ord_ost_id=2
go
exec sp_reset_connection
go
exec CheckAvailabilityAndUpdateOrderState @ord_id=68,@ord_ost_id=2
go
exec sp_reset_connection
go

Code:
connectionstring in web.config
<add name="TESTDB" connectionString="Server=XXXX\XXXXX;Database=XXX;User Id=XX;Password=XXXX"/>

Public Class clsDatabase
Private Function getConnection() As SqlConnection Dim sConnect As String Dim oConn As SqlConnection sConnect = ConfigurationManager.ConnectionStrings("TESTDB").ToString oConn = New SqlConnection(sConnect) oConn.ConnectionString = sConnect Return oConn End Function
Public Function executeSqlCommand(ByRef oCommand As SqlCommand) As SqlDataAdapter oCommand.CommandType = CommandType.StoredProcedure oCommand.Connection = getConnection() oCommand.Connection.Open() oCommand.ExecuteNonQuery() oCommand.Connection.Close() Return New SqlDataAdapter(oCommand) End Function
End Class Public Class clsOrder
Dim oSqlCmd As SqlCommand Dim oDataAdapter As SqlDataAdapter oSqlCmd = New SqlCommand("CheckAvailabilityAndUpdateOrderState") oSqlCmd.Parameters.AddWithValue("@ord_id", Me.Id) oSqlCmd.Parameters.AddWithValue("@ord_ost_id", Me.OtherId) oDataAdapter = oDb.executeSqlCommand(oSqlCmd) oDataAdapter.Fill(oDataSet, "XYZ")
End Class

Last edited by chris : 10-31-2007 at 07:47 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-01-2007, 02:14 AM
chris chris is offline
D-Web Trainee
 
Join Date: Oct 2007
Posts: 15
chris is on a distinguished road
Default Re: Stored procedure gets executed twice

I found the bug.
oCommand.ExecuteNonQuery() <- executes the sproc once.
oDataAdapter.Fill(oDataSet, "XYZ") <- executes it again.

*DOH*
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-01-2007, 03:08 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Stored procedure gets executed twice

great..I am also debugging and trying to resolve the same code in C#.........but u got....it ...ok good work
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure itbarota Database Support 3 03-10-2008 09:43 PM
how to get out parameter of stored procedure ? Murali PHP Programming 0 12-16-2007 04:57 AM
Stored procedure gets executed twice chris VB.NET Programming 0 10-30-2007 08:55 AM
difference between stored procedure and functions smani Database Support 5 08-26-2007 10:52 PM
Can a stored procedure call itself or recursive stored procedure? How many level SP n H2o Database Support 1 08-03-2007 10:55 AM


All times are GMT -7. The time now is 05:53 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0