Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2003, 01:37 AM
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple registration ok???

When you register users on ThePhile web app it seems its more than ok to have duplicate entries. I can for example enter the same user details over and over again and the app will keep on accepting it and put it into the database. So its more than alright to have many users with the same Email address, First name, last name, etc, etc.

There is a piece of code in the new.aspx.vb file which goes as follows:

If creationResult = CInt( _
        Wrox.WebModules.Accounts.ProcResultCodes.AccountAl readyOnFile) Then

        CreateError.Text = _
          "<br/>An account with that e-mail address is already on file.<br/>"
        CreateError.Visible = True

'---- etc etc

However this is never triggered. The primary key for the Users table is an integer which is an identity. If this were violeted (A situation which i think would be impossible considering that the database puts this value in itself and not the registering user) Then you would get an error for duplicate records which is handled in ThePhile code.

I can overcome this problem myself by simply adding in another function which would check to see if the regstering users email address already exists in the database and if so then supply the error that the email address is already in use on this site.

So i was just wondering whats the go? Is this a mistake? a bug? a forgotten method that was never written?

 
Old November 30th, 2003, 04:46 PM
Authorized User
 
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can prevent multiple registration. When adding a new user to the user table, your code is basically calling a stored procedure to insert into the user table.

Modify that that sp so that it first checks if the email is already in the database. If yes return something which you can use to show the message.
In my case it won't happen since I am using string userid for user registration rather than email and that userid is Primary key of the table. Duplicate userid will voilate the Primary key constraint.

Thanks
Musa

 
Old May 15th, 2004, 03:16 PM
Registered User
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What the authors intended to do, which they did not implement in the database design, was for SQL server to throw an error when you tried to insert a new user into the database where they had the same email as someone else already there. SQL Server would throw a 2601 or 2627 error, which can be detected. In order for your application to detect it, modify Data.Users.cs:

Code:
                if ((e.Number == 2601) || (e.Number == 2627)) 
                {
                    return (int) Wrox.WebModules.Accounts.ProcResultCodes.AccountAlreadyOnFile;
                }
                else 
                {
                    throw new AppException("An error occurred (" + e.Number.ToString() + ") while executing the Accounts_CreateUser stored procedure", e);
                }
Next, you need to modify the Accounts_Users table to make the email column an index. To do this, right-click on Accounts_Users, and choose Design Table. Then highlight the EmailAddress column, right-click, and choose Indexes/Keys... Click the New button, make sure the Column is set to EmailAddress, Check 'Create UNIQUE' and then select 'Constraint'.

I made those changes and it works now, as originally intended by the authors.

References:
http://doc.ddart.net/mssql/sql2000/h...err_1_2fu9.htm


Hope this helps,

Doug

 
Old May 16th, 2004, 09:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I already saw this code in Data.cs:

catch ( SqlException e )
{
    // 2601 is the number returned when the primary key
    // is violated. We know if we're violating the primary
    // key that the e-mail address is already on file.
    // Its cheaper than actually searching for that address before
    // inserting.
    if (e.Number == 2601)
    {
        return (int)Wrox.WebModules.Accounts.ProcResultCodes.Acco untAlreadyOnFile;
    }
...

The only change needed is to add a unique index on email address. But, this was already done in the updated database backup file included with the code download.

If anyone has not created their DB by restoring the DB backup, they will be missing a lot of additional SPs and other fixes. The DB Creation script in the code download has NOT been updated.

Eric
 
Old April 14th, 2005, 11:02 AM
Authorized User
 
Join Date: Mar 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

which file should i use from the code download to get the latest database files.

i have downloaded this filr=e
http://media.wiley.com/product_ancil...l-server-7.zip

But when i try to restore the db, i get an error:
"The backup set holds a backup of a dataabse other than the existing 'thephile'.."

Any idea what I need for the latest DB file

 
Old April 14th, 2005, 11:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You are trying to restore the SQL Server 7 backup file. You probably want to use the SQL Server 2000 backup file that comes with the code download.

If you try that one and it fails with a similar error, you may have to delete the existing database of that name before doing the restore.

Eric
 
Old April 14th, 2005, 02:08 PM
Authorized User
 
Join Date: Mar 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this file 'thephile-database-backup' comes with the code. I already have used this file to setup the DB. But still a lot of stored procedures are missing, like: sp_Accounts_GetPermissionsInCategory

Also, the Users table still has UserID as the primary key.

Am i missing something??

 
Old July 31st, 2005, 04:26 PM
Authorized User
 
Join Date: Jul 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by englere
 I already saw this code in Data.cs:

catch ( SqlException e )
{
    // 2601 is the number returned when the primary key
    // is violated. We know if we're violating the primary
    // key that the e-mail address is already on file.
    // Its cheaper than actually searching for that address before
    // inserting.
    if (e.Number == 2601)
    {
        return (int)Wrox.WebModules.Accounts.ProcResultCodes.Acco untAlreadyOnFile;
    }
...

The only change needed is to add a unique index on email address. But, this was already done in the updated database backup file included with the code download.

If anyone has not created their DB by restoring the DB backup, they will be missing a lot of additional SPs and other fixes. The DB Creation script in the code download has NOT been updated.

Eric

But in order to make it work properly, we still need to modify "if (e.Number == 2601)" to "if ( (e.Number == 2601) || (e.Number == 2627) )" as Drohm suggested above, otherwise I still got ugly error message.

2601 "Cannot insert duplicate key row in object '%.*ls' with unique index '%.*ls'."

2627 "Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'."

however, since I am just a beginner, I have no idea about what the difference is between those two error codes. Why my SQL Server 2000 throw a "2627" not a "2601" when I was trying to regist a duplicated user?

Gary






Similar Threads
Thread Thread Starter Forum Replies Last Post
Registration Form Help invisible bunny king Classic ASP Databases 7 February 5th, 2007 05:30 PM
COM+ components registration ajindal General .NET 1 September 1st, 2006 03:31 AM
server registration error aspnet79434319 SQL Server ASP 0 June 26th, 2005 07:52 AM
Registration database jacob C# 2 January 22nd, 2004 01:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.