NHibernate Saves Without Commit() Or Flush()?

May 18, 2010

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 Replies


Similar Messages:

C# - Force Query Execution Without Flush/commit

Feb 16, 2010

i 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.

View 6 Replies

What Is The Usage Of Flush

Aug 17, 2010

I always have problem with the conception of flush who knows exactly what it means eg:

[Code]....

View 1 Replies

How To Handle Response.flush

Jun 21, 2010

I am using Response.flush() method for download the csv file. I am create the html on page and call the Response.flush method. It is working good But when i am cancel the download and do the another operation , It genrates the error.

View 6 Replies

VS 2008 Looking For Map Program That Saves Jpeg?

Sep 24, 2010

I have an ASP.NET website where we are generating pdf's and web pages using crystal reports. One of the requirements we have is for in the pdf's to have a map of NY state with markers on it that are placed based on GIS Coordinates. For the web page we can do this easily with google maps. if there are any third party map generating solutions that can do this? We currently use map info and google maps, but I dont think either are capable of doing this?

View 3 Replies

Create Web Page - Saves As Pdf File On Clicking

Jul 19, 2010

I am wondering if it is possible (for as little money as possible) to create a web page that when a user clicks the submit button saves a file as a PDF. it is going to be used as a purchase order creator on a webpage. I have seen a few tutorials around but they seem to use software that requires purchasing a license.

View 4 Replies

VS 2008 - Uppercase Textbox Saves As Lowercase?

Feb 1, 2010

I'm using this style text-transform:uppercase to convert to uppercase in a textbox. Works fine, but it saves as lowercase.

View 3 Replies

DataSource Controls :: DataSet Saves DB Name In DbObjectName?

Feb 19, 2010

I am having an issue with the DataSet saving the name of the Database that the table or query is ran from in the .xsd inside the DbObjectName even though it is being called from the connectionstring in the web.config file. I have the following line in the connectionstring setting the initial catalog to the DB name:

[Code]....

the line adds the DB name (dbName_Sandbox.dbo.MySQLScript) automatically, how do I stop this and only have dbo.MySQLScript?

Example of someone else having same issue, but they just did a mass find replace, I don't want to do this every time I have to create a DataSet then deploy to the production server.

[URL]

View 1 Replies

MVC :: 2 NerdDinner - Data No Longer Saves After Adding ViewModel

Sep 3, 2010

I am creating the NerdDinner application via the Professional ASP.NET MVC 2 book, and once I got to the ViewModel part (pages 88-91), I noticed none of my data was saving any longer. I discovered several errors and areas of confusion in these pages of the book, which I will list now.

Page 88: When it says to add the DinnerFormViewModel class, it doesn't say what folder to add it to. On page 89, the Inherits example (NerdDinner.Controllers.DinnerFormViewModel) implies it was added to the Controllers folder, but if that were so, the code on page 88 would need to use Models.Dinner instead of just Dinner. No big deal; just put it in Models and change the Inherit statement on page 89 to use NerdDinner.Models.DinnerFormViewModel.

Page 89: At the bottom of the page is some wrong code. Since the properties of Dinner are now one level deeper, all references to m.Title, m.Country, etc, need to be m.Dinner.Title, m.Dinner.Country, etc. The statements above the code are also incorrect ("Notice... we are not changing the names of the input elements... the form elements will still be named...") -- the form elements will actually change from "Title", "Country", etc to "Dinner_Title", "Dinner_Country", etc.

Page 90 (Code Snippet 1-53): This was the one that broke the data saving. Now that the form elements have prefixes, the TryUpdateModel(dinner) needs to pass a prefix, like TryUpdateModel(dinner, "Dinner"). This will append "Dinner_" to the element names so that they can be found on the form.

View 3 Replies

Render Output To String - Response.Flush Breaking Page Caching

Feb 3, 2010

I have some code that is used to replace certain page output with other text. The way I accomplish this is by setting the Response.Filter to a Stream, Flushing the Response, and then reading that Stream back into a string. From there I can manipulate the string and output the resulting code. You can see the basic code for this over at [URL] However, I noticed that Page Caching no longer works after the first Response.Flush call.

I put together a simple ASP.NET WebApp as an example. I have a Default.aspx with an @OutputCache set for 30 seconds. All this does is output DateTime.Now.ToLongTimeString(). I override Render. If I do a Response.Flush (even after the base.Render) the page does not get cached. This is regardless of any programmatic cacheability that I set. So it seems that Response.Flush completely undermines any page caching in use. Why is this?

extra credit: is there a way to accomplish what I want (render output to a string) that will not result in Page Cache getting bypassed?

ASPX Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCacheVsFlush._Default" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<%= DateTime.Now.ToLongTimeString() %>

Code-behind (Page is Cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
Code-behind (Page is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Flush();
}
Code-behind (Page still is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
Response.Flush();
}

View 1 Replies

Commit Transaction In SQL Server

Dec 10, 2010

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

View 2 Replies

C# - LINQDATASOURCE Do Not Commit To Database Straight Away?

Nov 6, 2010

I'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 Replies

Commit And Rollback Options In Database

Apr 27, 2010

I 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]...

View 2 Replies

SQL Server :: Begintrans And Commit For Records?

Jul 23, 2010

I 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 Replies

SaveChanges() Does Not Commit Changes To The Database And Entity Framework

Nov 7, 2010

All 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 Replies

ADO.NET :: Explaination About Commit,rollback,tranasaction. With Examples?

Aug 20, 2010

i have no idea about commit,rollback,tranasaction can any one explain with examples brefiely.

View 2 Replies

C# - Bind A Grid To An Anonymous LINQ Result, Then Commit Changes To DB?

Mar 4, 2011

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.

View 1 Replies

Active Directory/LDAP :: Commit Changes Error While Updating To The AD?

Jan 8, 2010

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 Replies

DataSource Controls :: Reader.close() And Transaction.commit()?

Feb 8, 2010

I'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 ?

View 3 Replies

DataSource Controls :: Check Constraints Are Applied Only After A Commit?

Apr 9, 2010

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?

View 5 Replies

Web Forms :: How To Commit And Roll Back Transactions From Code

Dec 17, 2013

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]...

View 1 Replies

DataSource Controls :: Transaction Count After EXECUTE Indicates A Mismatching Number Of BEGIN And COMMIT Statements?

May 27, 2010

I have a stored procedure which is part of the aspnetdb but i am using my own database and therefore these stored procedures are added on my sql server locally.So i uploaded the databases to my hosting company 1and1 and created the stored procedures and tables as those in aspnetdb but i get the error as in the title. this is a standard stored procedure which lives in the aspnetdb database but not sure why this is happeningthe code is below which is for aspnet membership createuser a standard stored procedure

[Code]....

View 4 Replies

Flush Separate Castle ActiveRecord Transaction And Refresh Object In Another Transaction

Jun 15, 2010

I've got all of my ASP.NET requests wrapped in a Session and a Transaction that gets commited only at the very end of the request. At some point during execution of the request, I would like to insert an object and make it visible to other potential threads - i.e. split the insertion into a new transaction, commit that transaction, and move on. The reason is that the request in question hits an API that then chain hits another one of my pages (near-synchronously) to let me know that it processed, and thus double submits a transaction record, because the original request had not yet finished, and thus not committed the transaction record.

So I've tried wrapping the insertion code with a new SessionScope, TransactionScope(TransactionMode.New), combination of both, flushing everything manually, etc. However, when I call Refresh on the object I'm still getting the old object state. Here's some code sample for what I'm seeing:

Post outsidePost = Post.Find(id); // status of this post is Status.Old
using (TransactionScope transaction = new TransactionScope(TransactionMode.New))
{
Post p = Post.Find(id);
p.Status = Status.New; // new status set here
p.Update();
SessionScope.Current.Flush();
transaction.Flush();
transaction.VoteCommit();
}
outsidePost.Refresh();
// refresh doesn't get the new status, status is still Status.Old

View 1 Replies

How To Write The Date The Discription Row 2 = "Paid" And Saves Or Stores

Mar 23, 2010

I am using visual web developer 2008 vb code.The Code I used is like this. it works but doesnt Store or SaveI am using Formview / DetailsView in "Insert" ModeWhat I want is that When I finish writing The Date The Discription Row 2 = "Paid" and Saves or Stores

View 4 Replies

AJAX :: Asyncfileupload Control - Select A File It Saves Another File?

Jan 23, 2010

I am using this control to give the user the possibility to upload up to 5 pics. Well, it generally works fine but i started to test it using a folder full of pics. This folder contains more than 900 pics which are named from "DSC_8138.jpg" to "DSC_9255.jpg" (some has been deleted).

When i try to upload the pic "DSC_8138.jpg" it saves the pic "DSC_8168.jpg".

When i try to upload the pic "DSC_8141.jpg" it saves the pic "DSC_8147.jpg".

There is not any clear critieria in this.

I am quite sure that my code in the AsyncFileUpload1_UploadedComplete method cannot cause this problem. Actually, when i try to upload the pic "DSC_8141.jpg" the file name is still "DSC_8141.jpg" even though the pic uploaded is the "DSC_8147.jpg". in any case, the control deals with the uploading process.

[Code]....

[Code]....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved