perpetual_noob
perpetual_noob

Reputation: 33

Update query reaching SQL server but does not update the record and returns no error

This is the issue:

I have a table in which update queries are failing.

When a user clicks on a delete button in the application, RowStatus should be set as 0 instead of 1, the data type is bit. Using SQL profiler, we can see that the update query is reaching the SQL server, but it is not running there - it does not return any exception to the application. We are using the PK of the table to identify the row to be updated. We are able to successfully insert values into table from application via web server, only the update queries fail. We have muplitple tables in the application - but the issue is only for this table. We use entity framework for updating the table.

Can any one please help ?

This is the table structure:

[dbo].[TableName](
[PrimaryKey] [int] IDENTITY(1,1) NOT NULL,
[ForeignKey1] [int] NOT NULL,
[ForeignKey2] [int] NOT NULL,
[RowStatus] [bit] NULL,
[CreatedBy] [int] NULL,
[CreationDate] [datetime2](7) NULL,
[UpdatedBy] [int] NOT NULL,
[UpdatedDate] [datetime2](7) NOT NULL
)

This is the query i saw in profiler:

exec sp_executesql N'UPDATE [dbo].[TableName]
SET [RowStatus] = @0, [UpdatedBy] = @1, [UpdatedDate] = @2
WHERE [PrimaryKey] = @3)
',N'@0 bit,@1 int,@2 datetime2(7),@3 int',@0=0,@1=999,@2='2018-05-02 
05:20:16.2795067',@3=30

Update: It started working after i changed the dbcontext.savechanges() instead of dbcontext.savechangesasync() to save the changes to entity. Has anyone faced this issue before ?

Upvotes: 1

Views: 639

Answers (2)

perpetual_noob
perpetual_noob

Reputation: 33

I forgot to add 'await' keyword in the method call. That was causing this issue.

Upvotes: 1

avinash
avinash

Reputation: 183

If you are using Entity Framework try cleaning the project as some cache may stop your code to execute cleanly.

Upvotes: 1

Related Questions