logo
down
shadow

How to rollback saved changes in WebAPI


How to rollback saved changes in WebAPI

By : B. Nichelle Hicks
Date : November 16 2020, 06:23 AM
fixed the issue. Will look into that further Short answer: AFAIK, no. Once you have called saveChanges() the SQL statements were issued to your database and the database transaction has committed. The only way to roll that back would be something custom you implement, not a database transaction or EF data context thing.
Long answer: You are correct that each request into your API will have a different data context (based on your above code where you new up a context in the action method). Also, please reconsider wrapping all of your EF operation behind a repository. Here are some viewpoints from smart people that describe how this can needlessly complicate your code.
code :


Share : facebook icon twitter icon
Is it a better practice to explicitly call transaction rollback or let an exception trigger an implicit rollback?

Is it a better practice to explicitly call transaction rollback or let an exception trigger an implicit rollback?


By : user3209144
Date : March 29 2020, 07:55 AM
this will help Former. If you look up MSND samples on similar topics, like TransactionScope, they all favor the implicit rollback. There are various reasons for that, but I'll just give you a very simple one: by the time you catch the exception, the transaction may had already rolled back. Many errors rollback the pending transaction and then they return control to the client, where the ADO.Net raises the CLR SqlException after the transaction was already rolled back on the server (1205 DEADLOCK is the typical example of such an error), so the explicit Rollback() call is, at best, a no-op, and at worse an error. The provider of the DbTransaction (eg. SqlTransaction) should know how to handle this case, eg. because there is explicit chat between the server and the client notifying of the fact that the transaction rolled back already, and the Dispose() method does the right thing.
A second reason is that transactions can be nested, but the semantics of ROLLBACK are that one rollback rolls back all transactions, so you only need to call it once (unlike Commit() which commits only the inner most transaction and has to be called paired up for each begin). Again, Dispose() does the right thing.
Does a rollback inside a INSERT AFTER or UPDATE AFTER trigger rollback the entire transaction

Does a rollback inside a INSERT AFTER or UPDATE AFTER trigger rollback the entire transaction


By : Михаил Дзык
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Yes it will rollback the entire transaction.
It's all in the docs (see Remarks). Note the comment I've emphasised - that's pretty important I would say!!
Entity is not saved to database via WebApi call

Entity is not saved to database via WebApi call


By : Sonam
Date : March 29 2020, 07:55 AM
help you fix your problem Check your web.config section connectionStrings. Ideally you create a unique name for your connection string and use that name in the constructor of your DbContext. Even easier is to pass that name through in the default constructor to the parameterized constructor of DbContext.
MyDbContext.cs
code :
public class MyDbContext : DbContext
{
    public MyDbContext() : base("Name=bcard_portal")

    public DbSet<HelpRequest> HelpRequests { get; set; }
}
<connectionStrings>
  <add name="bcard_portal" connectionString="data source=servername;initial catalog=mydatabase1;user id=andrewb;password=hahayeahright;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
SQL Server : BEGIN TRAN ... COMMIT without ROLLBACK does not rollback depending on the error

SQL Server : BEGIN TRAN ... COMMIT without ROLLBACK does not rollback depending on the error


By : Hassan Shahid
Date : March 29 2020, 07:55 AM
I wish this helpful for you
But I am still wondering why the BEGIN TRAN without ROLLBACK does not work all the time. Does it really depend on the type of error as I guess?
TFS 'Get specific version, checkout/checkin' vs 'Rollback Entire Changeset' vs 'Rollback selection of changesets' vs 'So

TFS 'Get specific version, checkout/checkin' vs 'Rollback Entire Changeset' vs 'Rollback selection of changesets' vs 'So


By : user2764271
Date : March 29 2020, 07:55 AM
I hope this helps . When you right click on a file and Rollback... you got the pop-up, in the top you have the field Items to Rollback, by default the value there will be the server path to the file.
So when you do rollback from there the rollback will be only to this file and not impact other files.
Related Posts Related Posts :
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org