Avatar of RayBakker
RayBakker
Flag for Canada asked on

Stored Procedure Executes but New Record is not Kept

SQL Server 2008 Insert Stored Procedure Executes but the record does not stay.

1. Application calls the stored procedure, passing the data.
2. I see that the new record is created and is in the table.
3. Moved off of the page in the application.
4. The new record is gone.

ALTER PROCEDURE [dbo].[Procedure]
	
	@Document nvarchar(max),
	@UploadDate  DateTime,
	@Label nvarchar(max),
	@PermitID int
AS
BEGIN
	
	SET NOCOUNT ON;
  
	INSERT INTO [dbo].[Tablename](Document, UploadDate, Label, PermitID)
	VALUES(@Document, @UploadDate, @Label, @PermitID);

END

Open in new window


Any ideas?

Thanks
Microsoft SQL ServerSQL* Stored Proc

Avatar of undefined
Last Comment
Mark Wills

8/22/2022 - Mon
Dustin Saunders

Is there code in the application that saves back an original copy of the tables when navigating away?

If you set up a SQL Server Profiler trace, so you see an execution that removes the table?  Are there any triggers in the database that would delete the new rows?
slightwv (䄆 Netminder)

Does the transaction not get committed?  Moving off the page might rollback.
RayBakker

ASKER
slight

I am not using transaction. I am using a try/catch in my code. No errors are raised.

The page in question, allows the user to upload a file. Inserts a record that reflex the upload.

File gets uploaded, record gets created. When I click to go to another page, the record disappears. I can see that the sequence has incremented.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
slightwv (䄆 Netminder)

sequences get incremented even if DML is rolled back.

I'm not a SQL Server person so I'm not sure how it handles things but what you describe seems to be the insert getting rolled back.  Try an explicit commit and see if the row stays after you move off the page.
RayBakker

ASKER
slightwv

Thanks for the feedback. I agree that it seems like a rollback type issue. I did do an explicit commit but it make no difference. I am asking my DBA to look into how they created the database and the account that the application uses to connect to the DB.

I think it is a permission issue on the table.

I wrote some code, early in the project,that imports the data from the old oracle DB in to this SQL DB. I wrote the SQL statements (inserts, selects, updates) in code. They all worked.  It used that same account to connect to the SQL DB.

 I am at a loss to explain how the SQL statements in code and the stored procedure connecting to the DB with the same account give different results.

Does that spark anything with you?

Tanks for your time

Ray
slightwv (䄆 Netminder)

I don't see how it can be a permission issue.  I've never seen a permission that would allow a "temporary" insert but not commit without any error.

Is it possible you are looking at different databases/schemas(inserting into one and looking in another)?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
RayBakker

ASKER
I am calling the store proc from code, using the connection.

1. Run the app that calls procedure and insert.
2. I log into SQL Server Management Studio and see the new record in the table.
3. In the app I go to the new page.
4. In SQL Server Management Studio and rerun that select and the record is gone.
5. Of course I am logging into Studio with my personal account.
6. My Selects work from my app.

Just tested my update and it worked (different table).

Sincerely

Ray
slightwv (䄆 Netminder)

You can investigate Dustin's ideas.

Hopefully a SQL Server Expert will be along later.
Mark Wills

Sounds like there isnt any write permission. That would be specific for the User (and table)

It is suspiciously rolling back or contravening constraints / referential integrity issues. That should be applicable to all, and generate an error.

I would be using a BEGIN TRANSACTION ....  COMMIT TRANSACTION within the SP as we see it. But you also mention a TRY CATCH block which I cannot see.... a BEGIN TRANS without a COMMIT will also give you that type of behaviour.

Can you show the (full) trigger and the SP ?

Whats the connection string ?

Have you checked permissions in SSMS for the User / Role / Table ?

Have you tried (or ever used) sql profiler before ?

https://blogs.msdn.microsoft.com/syedab/2009/09/16/how-to-use-sql-server-profiler-to-help-in-debugging-applications/
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
RayBakker

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mark Wills

Ouch :)

Thanks for letting us know....