Stored Procedure Executes but New Record is not Kept

RayBakker
RayBakker used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dustin SaundersCo-Founder and Chief Architect
Top Expert 2016

Commented:
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?
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
Does the transaction not get committed?  Moving off the page might rollback.
RayBakkerApplication Developer Analyst

Author

Commented:
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.
Ensure you’re charging the right price for your IT

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

Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
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.
RayBakkerApplication Developer Analyst

Author

Commented:
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
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
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)?
RayBakkerApplication Developer Analyst

Author

Commented:
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
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
You can investigate Dustin's ideas.

Hopefully a SQL Server Expert will be along later.
Mark WillsTopic Advisor, Page Editor
Distinguished Expert 2018

Commented:
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/
Application Developer Analyst
Commented:
Greetings

Thanks you all for you assistance. I discover MY issue. When I was originally testing I would always click on the link "Home" after to wrote a record to the table in question. I tried clicking on other links after inserting the record and the record stayed until I clicked "Home".

I have forgotten that I wrote some maintenance code that removed old records based on a date from another table. I quick look at that store procedure and I discover my issue.

That you all for your assistance.
Mark WillsTopic Advisor, Page Editor
Distinguished Expert 2018

Commented:
Ouch :)

Thanks for letting us know....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial