Unable to execute Stored Procedure in Management studio but can execute in Visual studio Debug mode

Hi,
  I just attached a stored procedure which I am trying to execute in management studio. I am using a cursor to update the table in sql server 2005.

exec EXEC [sp_SiteUpdate] @PaymentID = 123456.
I get the message 'Command(s) completed successfully.' though the table is not updated

But if I execute the same stored procedure in debug mode in visual studio, I am able to update the table and the message I get,

'(3 row(s) affected)
(0 row(s) returned)
@RETURN_VALUE = 0
Finished running [dbo].[sp_SiteUpdate].
The thread 'db01 [98]' (0x13c4) has exited with code 0 (0x0).
The program '[1796] [SQL] db01: db01' has exited with code 0 (0x0).

Does anyone know what's wrong with the stored procedure?

Thanks,
HK

CREATE PROC [dbo].[sp_SiteUpdate](
@PaymentID nvarchar(50))
 
AS
 
--SET NOCOUNT ON
 
DECLARE  @LeanLoadID nvarchar(50)
DECLARE @InvoiceSite nvarchar(50)
DECLARE @GroupInfo nvarchar(50)
DECLARE @RowsAffected int
 
SET @RowsAffected = 0
 
DECLARE invoicesite_cursor CURSOR FOR 
SELECT leanloadID FROM PAYMENT LP,LOAD LL
WHERE LP.PAYMENTID = LL.PAYMENTID AND LP.PAYMENTID = @PaymentID
ORDER BY LL.LEANLOADID
 
OPEN invoicesite_cursor
 
WHILE @@FETCH_STATUS = 0
BEGIN
 
FETCH NEXT FROM invoicesite_cursor 
INTO @LeanLoadID
 
SELECT @InvoiceSite = S.LOCATIONREF,@GroupInfo = GROUPINFORMATION
FROM LEANWS_LOAD L
LEFT OUTER JOIN
(SELECT LOCATIONREF,LEANLOADID  FROM STOP WHERE LOCATIONREF IN('1','2','3') AND LEANLOADID = @LeanLoadID) AS S ON L.LEANLOADID = S.LEANLOADID
WHERE L.LEANLOADID = @LeanLoadID
 
SET @InvoiceSite = ISNULL(@InvoiceSite,0)
 
IF @InvoiceSite = '1'
   SET @InvoiceSite = 'TXHQ'
ELSE IF @InvoiceSite = '2'
   SET @InvoiceSite = 'KNOX'
ELSE IF @InvoiceSite = '3'
   SET @InvoiceSite = 'ARIZ'
ELSE
   SET @InvoiceSite = @GroupInfo 
 
UPDATE LOAD SET INVOICESITE = @InvoiceSite
WHERE LEANLOADID = @LeanLoadID
SET @RowsAffected = @@ROWCOUNT
 
 
END 
CLOSE invoicesite_cursor
DEALLOCATE invoicesite_cursor

Open in new window

computer12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
If you are running from SSMS, Have you committed the procedure after it is executed.
If you haven't committed, then it wont be reflected in that table.

Kindly check whether you have set your SET IMPLICIT_TRANSACTIONS set to ON accidentally.

Switch it OFF to autocommit statements.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
computer12Author Commented:
I added SET IMPLICIT_TRANSACTIONS OFF to my stored procedure and it still had the same problem. Is this problem because of using cursor in stored procedure?
0
computer12Author Commented:
Any thoughts?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

corptechCommented:
Change your first test to:  EXEC sp_SiteUpdate '123456' and see if you get the correct results.  There isn't anything wrong with the stored procedure other than
the syntax of this call.  The second test is returning 0 exit code (successful code in SQL Server).
0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
>> I added SET IMPLICIT_TRANSACTIONS OFF to my stored procedure and it still had the same problem. Is this problem because of using cursor in stored procedure?

I mentioned not to include this one in your procedure but to execute that in SSMS query window.
Once set to OFF, execute your procedure and now it should work.

Hope this clarifies.
0
computer12Author Commented:
It did work the first time after I set it to OFF then executed the procedure.
1. But the next time, I did not set it to OFF and executed the procedure. This time the stored procedure didnot work.
2. I tried directly with out setting it to OFF to execute the procedure, but it didnot work.
0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Ok... Just try this one out in your Query Window

Hope this helps


SET IMPLICIT_TRANSACTIONS OFF;
GO
 
EXEC [sp_SiteUpdate] @PaymentID = 123456

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.