ADO.NET :: Explaination About Commit,rollback,tranasaction. With Examples?
Aug 20, 2010i have no idea about commit,rollback,tranasaction can any one explain with examples brefiely.
View 2 Repliesi have no idea about commit,rollback,tranasaction can any one explain with examples brefiely.
View 2 RepliesI have this page in my application that contains a couple of grids and a few text boxes. Now these grids are getting populated from a hidden field in the page. My requirement is like the main page should have an "Update All" button where as these grids have their individual Update and delete options. Now when I delete or update anything from the Grids it should do a soft update or delete function and eventually when I hit "Update All" an actual commit statement should be executed.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
begin
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
TextBox PhoneNo = (TextBox)row.FindControl("TextBox2");
[code]...
I am using LINQ to SQL in my application. I have some fields like textbox and checkbox in my form. when i enter any text in textbox it should search the data in the database. it should display in some control. Here i want to write query in LINQ I want to use predicate builder. If we are using sql server we have to write in stored procedure but i dont want in stored procedure. plz tell how to use predicate builder and explaination.
View 1 Repliesi want to rollback the changes if something goes wrong either in the clients sit(internet connection failed in the time the sub is running) or in the servers side(if the server falls)is the sqltrasnsaction the properly solution??
Code:
Dim thisConnection As New SqlConnection("server=(local)SQLEXPRESS;" & _
"integrated security=sspi;database=MyDatabase")
' SQL Delete Commands
Dim sql As String = "DELETE FROM Employee " & _
"WHERE ID = 10"
' Create command
[code]...
I have written several queries under one single transaction. When any of the query throws an error then the whole transaction should rollback. However, in some rare cases say 2% cases even after the error the next transaction is getting comitted.
note that all transaction processes (opening, committing and rollback) is done through .net.
I am using 64bit windows 2003 for data and application server. And website is configured for runapp32on64.
in sql server 2005, i have deleted row by mistake and now want to roolback them, i wrote a query is "delete tblmetric" nd pressed F5 now wanna to recover the rows
View 4 RepliesI am using more than one files to read and write to the server. Suppose during writing or reading any of files gets error the already stored files need to be rollback or removed from storing.So that the user agin try to write without error. Simply the all of the files need to be stored into the server without error, of error occurs to any of file none of files need to be read/write
View 2 RepliesSuppose say I am doing a couple of operations.
First a delete and then an insert.
Now, these two operations are done with two different connections (say con1 and con2). Both these connections are enlisted in the same TransactionScope.
Before the delete/insert operations the connections are opened and immediately closed.
So, now if the insert fails, then how is the delete rollbacked since con1 has been closed?
I have the web form whcih processing several web services calls.
If one call failed, it will rollback transactions. But it cannot.
Due to the web services will complete for each call.
I am using sql connection and sql command.
Is it possible to do this?
User amends an existing order. The order is complex - lots of related 'entities' (addresses, post options, suppliers, makes, models, various items etc). Across multiple http posts.
User wants to discard the changes.
I have an order entity and as the user is editing this I am making various changes to the entity associations e.g changing order.address, order.items.add(item)...
In a single post this is fine, but across posts I don't know how best store state. If I store the entities then I cannot save the changes as they are across different data contexts. I have read that it is bad practice to store the data context in the session state i.e. long-lived context. I can't save changes after each edit/post because I cannot roll-back (?). I really would like to work with the entities during the editing process rather than one big save at the end (taking UI settings and applying these in one chunk).
table 1
[Code]....
Table 2
[Code]....
my stored procedure
[Code]....
when ever i m passing the wrong the value in second table while updating its not updating the table but the problem it is inserting the value in first table i want the whole trans should proceed if success if not rollback
I have a strange situation.An ASP.NET button click event causes an object in memory to be updated. The object was loaded from NHibernate via Refresh() during Page_Load, but at no time during the entire page life cycle is Commit() or Flush() called.At some point after the page's OnUnload step, the object and any changes made to it are automatically persisted to the database. I cannot see when or where or why this occurs.
View 2 RepliesI'm using a LinqDataSource with a RadGrid. When I Add a new Grid item and click insert the values are immediately saved to the database.Is there a way where they can be actually not put in the database until I give the command?
View 1 RepliesI have 20 records in the datatable and i try to insert this records in a database, i want towrite begintransactions , and if all the records correct , i need to commit otherwise i need to rollback.how to do this?
View 2 RepliesAll I am trying to do is to make an update to an existing User and then save the changes to the database. I fooled around with different options and can see that I can make the change to the context during Page_Load, but it does not commit the changes to the Database.
View 5 Repliesi am using the transaction-per-request (session-in-view) pattern for an asp.net web application. I have a couple of points in the application where i want to Save an NHibernate managed entity and then do a couple of more inserts and updates using common sql. These inserts/updates depend on the ID that the NH saved entity will take.
The problem is that the generated id does not exist in the transactions' scope. If i force a flush/commit the id is persisted but if the inserts/updates fail i have to rollback but the flushed/committed entity will not. Currently I'm doing a manual insert for these cases but that is something i want to change. So, is there a way to execute the SQL statement (inside the already open transaction) after the Save() but without forcing a flush/commit?
EDIT: I'm adding a semi-pseudocode example, i got 4 wrong answers so i think people don't understand (how NHibernate works)
At the Begin request i issue a
nhsession.BeginTransaction()
then at some point i do
FooClass fc = new FooClass("value");
nhsession.Save(fc);
ITransaction trans = nhsession.Transaction;
SqlCommand sc = new SqlCommand("some insert/update query that depends on fc's id", (SqlConnection)nhsession.Connection);
sc.Parameters.Add("id", fc.Id); //NHibernate generates the id, note i'm using assigned/hi-lo so no round trip to the db takes place
transaction.Enlist(sc);
try {
sc.ExecuteNonQuery();
}
catch (SqlException ex){
transaction.RollBack();
nhsession.Close();
}
and at the end of the Request i issue a CommitTransaction() and nhsession.Close()
Now this will do absolutely nothing: the FooClass (fc) has not been flushed/commited to the database. The Save() operation that NH has done is up to that point in-memory. That means no sql command has been issued by nhibernate and that means that the SqlCommand (sc) that i fire afterwards will fail miserably as the id does not exist.
If i do a flush/commit between Save() and the SqlCommand the FooClass(fc) _cannot_be_rolled_back_ and that is a bad bad thing.Currently, for this to work i make vanila sql insert using an SqlCommand, and i want to change that. (Why? because i don't want to make vanilla inserts they are susceptible to errors due to schema/model changes, and i got the OR/M for that)
How? i want to notify NHibernate somehow to execute the SqlCommand to corresponds to the Save() insert (hell, it can do all the SqlCommands it has gathered) but without it commiting or flushing!.
Currently i'm also searching for the prepared sql statement that nhibernate produces when flushing/commiting a saved object. Maybe i can just take that string and run it in my SqlCommand that is enlisted in the Transaction.
I've been looking into how best to do this and wisdom would be appreciated. For read only purposes, I've been happily using LINQ and binding it to a grid. For editing purposes, I've used the LinqDataSource control, enabled the Edit/Delete operations in the process, and I have a nice editable grid bound to some or all of the table's fields.Now I have a situation where I want to edit a few fields in table A, but there are various values in linked table B that I want to display in that grid too (no editing of those). So my query looks like the below. The fields in tblDupes (cleared, notes) are what I want to edit, but I'd like to display those tblVoucher ones.
var theDupes = from d in db.tblDupes
where d.dupeGroup == Ref
select new
[code]...
A similar but different question LINQDataSource - Query Multiple Tables? sent me looking at scott Guthrie's blog entry http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx, where he handles various events to have a LinqDataSource with a custom query across tables. This still seems aimed at explicitly designed classes though, even if the class has only a subset of the fields.
So my question is: is there an easy way to allow committing of the changes made to the anonymous collection (a changes.Submit type action), or just an easy way to 'display' fields from another table while not involving them in the updating?EDIT: Thinking more, it doesn't have to be anonymous really. I'd be happy to define a class to contain the elements in that query, since it won't change often. But, those elements would be across two tables, even though only one needs updating. Not sure if that suggests entity framework would be more suitable - I get the feeling it wouldn't - I don't want the whole 'model' always grouping the fields in this way.
answer this:I ran into the following error while trying to Update the user details on the Active Directory:General access denied error
View 2 RepliesI'm getting "This SqlTransaction has completed; it is no longer usable" exception when try to commit my transaction after sqlreader is close.Here is the code sample
[Code]....
...so when I get to commit the transaction it raises the mentioned exception: "This SqlTransaction has completed; it is no longer usable". I have also noticet that Command.Transaction becomes NULL after reader.Close()My question is: Can I use SqlDataReader and SqlTransaction ? Maybe to use BeginExecuteReader and EndExecuteReader ?
I have a multi- statement transcation in my stored procedure, that is either inserting or updating records in table1 and table2.
table1 has a check constraint. Will the check constraint be checked only after I call COMMIT in above transaction, OR will it be checked before I call COMMIT when using INSERT or UPDATE statement?
I just want to know the concept of commit Transaction and Begin Transaction in Asp.net with c# language, I have a certain code in c# given below... where I declare commit transaction and begin transaction. my code is:
public void dial(string traid, string trakey, string account, string ttref)
{
try
{
string[] result = new string[4];
SqlConnection sqlconn_cms = new SqlConnection(sqlconn_cmsstr);
[code]...
I am new to ASP.NET. Presently I have also been reading Object Oriented Programming(OOP).Could someone give me some simple examples how OOP are used in asp.net
View 4 RepliesAfter trying to adapt quite a few examples, I am still at a loss as how to acomplish what in old vb was a simple task.
Our clients send us files, which we compact into one large file and forward the compacted file to a third pary which in turn sends us back an XML report of the files recieved within the compacted file. I read this xml file and update a table marking the files that were send as 'completed' This process may take 5 - 10 minutes, and what I would like to do is ; when the user clicks the button to 'send' the compacted file, either , 1. disable the screen controls and display a message .. somthing like ' waiting for conformation '
or
2. show an animated dialog box with a message until we recieve the xml report back, then the message dissapears, controls are enabled. I have written the code to read the Xml report and the way I was thinking of doing this was once the user clicks the send, i do a watch directory until the file is
recieved back. The problem I have is how to create the message, hide and show it from a vb code behind function. All the examples I have seen are either way over my head in programming levels, or require a 'close' button on the 'message' screen
We plan to develop a ASP.NET ( VS 2010 ) web site.We need to know if there are any ready made startup ASP.NET web sites so we can get them and adjust / upgrade according to our needs.
View 1 Repliescan any one please provide me the links as how to write URL rewriting with ISAPI and asp.net in c#
View 1 Replies