[SOLVED] Unique Index Constraint - Not Throwing Exception

Posts   
 
    
Dave avatar
Dave
User
Posts: 48
Joined: 28-Jan-2004
# Posted on: 29-Apr-2004 22:10:38   

I have an account number field, which isn't the primary key, of a client entity that is set as an index with a unique constraint.

When using a Self-Service Template and doing a .Save() on the client with a non unique account number, the entity is not throwing an exception letting me know it could not be saved.

Is this expected behavior or am I doing something wrong? I would expect an exception.

Thanks,

Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 29-Apr-2004 22:13:11   

The exception from the db should bubble up into the code, as the unique constraint should force the database to throw the exception. In your case, the unique value is added to the db? You are also positive the exception isn't swallowed by code right next to the save?

Frans Bouma | Lead developer LLBLGen Pro
Dave avatar
Dave
User
Posts: 48
Joined: 28-Jan-2004
# Posted on: 29-Apr-2004 22:27:40   

Here is the code in question. Standard code that I have used successfully in the past and just merged it to use LLBLGenPro. The record is not being saved and the two lines below "AddTheClient" never get executed. The catch is also not executed.

private void btnAdd_Click(object sender, System.Web.UI.ImageClickEventArgs e) { if (Page.IsValid) { try { string _title; int _id = AddTheClient(out _title); // LogModification(_id, _title, "Added"); DataEntryArea.Visible = false; SuccessArea.Visible = true; } catch (Exception ex) { DisplayError(ex.Message); } } else { DisplayError("Invalid Information."); } }

private int AddTheClient(out string title) { ClientEntity _newClient = new ClientEntity();

_newClient.AccountNumber = txtAccountNumber.Text.Trim();
_newClient.Title = txtTitle.Text.Trim();
_newClient.Address = txtAddress.Text.Trim();
_newClient.Address2 = txtAddress2.Text.Trim();
_newClient.City = txtCity.Text.Trim();
if (ddlStateId.SelectedValue != "0") _newClient.StateId = Int32.Parse(ddlStateId.SelectedValue);

_newClient.ZipCode = txtZipCode.Text.Trim(); _newClient.Country = txtCountry.Text.Trim(); _newClient.Phone = txtPhone.Text.Trim(); _newClient.Fax = txtFax.Text.Trim(); _newClient.EmailAddress = txtEmailAddress.Text.Trim(); _newClient.WebsiteUrl = txtWebsiteUrl.Text.Trim(); _newClient.DefaultCommissionCheckPayee = txtDefaultCommissionCheckPayee.Text.Trim(); _newClient.DefaultBuyerClosingsCostTypeId = Int32.Parse(ddlDefaultBuyerClosingsCostTypeId.SelectedValue); _newClient.DefaultBuyerClosingsCostAmount = txtDefaultBuyerClosingsCostAmount.Text.Trim(); _newClient.DefaultSellerClosingsCostTypeId = Int32.Parse(ddlDefaultSellerClosingsCostTypeId.SelectedValue); _newClient.DefaultSellerClosingsCostAmount = txtDefaultSellerClosingsCostAmount.Text.Trim(); _newClient.Notes = txtNotes.Text.Trim(); _newClient.CreateBy = HttpContext.Current.User.Identity.Name;

_newClient.Save();

title = _newClient.Title;

return _newClient.Id; }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 30-Apr-2004 10:12:53   

Dave wrote:

Here is the code in question. Standard code that I have used successfully in the past and just merged it to use LLBLGenPro. The record is not being saved and the two lines below "AddTheClient" never get executed. The catch is also not executed.

What exactly do you mean 'the lines below AddTheClient never get executed? Where is the execution continued then? Could you step through the code in the debugger for me, please? If these statements are not executed, something might 'hang' on a lock somewhere.

Frans Bouma | Lead developer LLBLGen Pro
Dave avatar
Dave
User
Posts: 48
Joined: 28-Jan-2004
# Posted on: 30-Apr-2004 14:16:05   

Ugh... My apologies. I am a putz.

The exeption was triggering, but I am displaying the error in a javascript alert box, which did not like the message string returned by the exception. Therefore, it didn't display the alert box, which caused me to think the exception wasn't handled.

My apologies for wasting your time.

Regards,

Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 30-Apr-2004 14:33:10   

simple_smile Thanks for the info. I'm glad it's sorted out. simple_smile

Frans Bouma | Lead developer LLBLGen Pro