sql server - EXEC statement in SQL stored procedure's cursor loop -


i have following code in stored procedure. seems sometimes, execute statement doesn't execute @id values. ideas? happens if exec statement takes long time in cursor loop? in other words, exec statement synchronous or asynchronous? thanks!

declare @id int declare cur cursor local      select id         wq       convert(date, deploy_dt) = convert(date, getdate())         , stage_id = 6  open cur      fetch next cur @id      while @@fetch_status = 0 begin          exec uspupdpublishbywqid @id          fetch next cur @id     end  close cur deallocate cur 

update:

thanks hans. catch exceptions, if goes wrong , save database. see following error today:

system.data.sqlclient.sqlexception (0x80131904): timeout expired. timeout period elapsed prior completion of operation or server not responding. ---> system.componentmodel.win32exception (0x80004005): wait operation timed out @ system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action1 wrapcloseinaction) @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose) @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready) @ system.data.sqlclient.sqlcommand.runexecutenonquerytds(string methodname, boolean async, int32 timeout, boolean asyncwrite) @ system.data.sqlclient.sqlcommand.internalexecutenonquery(taskcompletionsource1 completion, string methodname, boolean sendtopipe, int32 timeout, boolean asyncwrite) @ system.data.sqlclient.sqlcommand.executenonquery() @ bcpublish.publish.publishtasks() clientconnectionid:10786fb0-c091-446f-adca-7f359131f731

just wondering, if there timeout error, why worked ids???

it seems sometimes, execute statement doesn't execute @id values. ideas?

try add print statement or debug ids being used. i'd test run select statement see ids supposed used.

are exec statements synchronous or asynchronous?

exec statement synchronous. exec statement might start, example, sql agent job can run asynchronously beside point.

what happens if exec statement takes long time in cursor loop?

your cursor take longer run...


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -