Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: help


Message #1 by nusrat sarwar <nusratsarwar@y...> on Fri, 21 Dec 2001 12:18:02 -0800 (PST)
hello all!

I am getting this error

although data is being inserted even with this error.

I wanna redirect the user but desired function is not

performing



Error Type:

Microsoft OLE DB Provider for ODBC Drivers

(0x80040E14)

[Microsoft][ODBC Microsoft Access Driver] The changes

you requested to the table were not successful because

they would create duplicate values in the index,

primary key, or relationship. Change the data in the

field or fields that contain duplicate data, remove

the index, or redefine the index to permit duplicate

entries and try again.

/baby/insertuser.asp, line 34





Browser Type:

Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt



where in my code I am wrong:



<% @Language=VBScript%>

<% Option Explicit %>



<% 



Dim username, password, duplicate,strconn, objConn,

objRS,SQL

strconn = "DRIVER=Microsoft Access Driver

(*.mdb);DBQ=" & Server.MapPath("/myfolder/mydb.mdb") 

set ObjConn=server.createobject("adodb.connection")

ObjConn.open strconn

username=trim(request.form("username"))

password=trim(request.form("password"))

duplicate=false 

If username = "" then

response.redirect "newuser.asp?error=1"

else

If password = "" then

response.redirect "newuser.asp?error=1"

End If

End If

'Now we create our recordset object that will create

the user's record

Set objRS = Server.CreateObject("ADODB.Recordset")



objRS.Open "users", objConn , 2,2



Do While Not (objRS.EOF OR duplicate) 

 If duplicate=true  then

response.redirect "newuser.asp?error=2"



End If

objRS.MoveNext

Loop 



SQL = "INSERT INTO users(username,password) VALUES

('"&username&"','"&password&"')" 

objConn.execute SQL





objRS.Close

Set objRS = nothing

objConn.Close

Set objConn = nothing



Response.redirect "newuser.asp?success=1"

%>

please help

prompt answer will be appreciated

regards

nusrat







__________________________________________________

Do You Yahoo!?

Send your FREE holiday greetings online!

http://greetings.yahoo.com

Message #2 by "TomMallard" <mallard@s...> on Fri, 21 Dec 2001 12:53:07 -0800
Pretty certain all you need to do is add...



on error resume next



after you execute the sql for access db's. That said, have you checked if

the fields you are inserting allow nulls, dup's, and so on? Sometimes that

will produce the error msg's you're getting.



tom mallard

seattle

----- Original Message -----

From: "nusrat sarwar" <nusratsarwar@y...>

To: "ASP Web HowTo" <asp_web_howto@p...>

Sent: Friday, December 21, 2001 12:18 PM

Subject: [asp_web_howto] help





> hello all!

> I am getting this error

> although data is being inserted even with this error.

> I wanna redirect the user but desired function is not

> performing

>

> Error Type:

> Microsoft OLE DB Provider for ODBC Drivers

> (0x80040E14)

> [Microsoft][ODBC Microsoft Access Driver] The changes

> you requested to the table were not successful because

> they would create duplicate values in the index,

> primary key, or relationship. Change the data in the

> field or fields that contain duplicate data, remove

> the index, or redefine the index to permit duplicate

> entries and try again.

> /baby/insertuser.asp, line 34

>

>

> Browser Type:

> Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt

>

> where in my code I am wrong:

>

> <% @Language=VBScript%>

> <% Option Explicit %>

>

> <%

>

> Dim username, password, duplicate,strconn, objConn,

> objRS,SQL

> strconn = "DRIVER=Microsoft Access Driver

> (*.mdb);DBQ=" & Server.MapPath("/myfolder/mydb.mdb")

> set ObjConn=server.createobject("adodb.connection")

> ObjConn.open strconn

> username=trim(request.form("username"))

> password=trim(request.form("password"))

> duplicate=false

> If username = "" then

> response.redirect "newuser.asp?error=1"

> else

> If password = "" then

> response.redirect "newuser.asp?error=1"

> End If

> End If

> 'Now we create our recordset object that will create

> the user's record

> Set objRS = Server.CreateObject("ADODB.Recordset")

>

> objRS.Open "users", objConn , 2,2

>

> Do While Not (objRS.EOF OR duplicate)

>  If duplicate=true  then

> response.redirect "newuser.asp?error=2"

>

> End If

> objRS.MoveNext

> Loop

>

> SQL = "INSERT INTO users(username,password) VALUES

> ('"&username&"','"&password&"')"

> objConn.execute SQL

>

>

> objRS.Close

> Set objRS = nothing

> objConn.Close

> Set objConn = nothing

>

> Response.redirect "newuser.asp?success=1"

> %>

> please help

> prompt answer will be appreciated

> regards

> nusrat

>

>

>

> __________________________________________________

> Do You Yahoo!?

> Send your FREE holiday greetings online!

> http://greetings.yahoo.com

>




$subst('Email.Unsub').

>



Message #3 by nusrat sarwar <nusratsarwar@y...> on Fri, 21 Dec 2001 12:51:10 -0800 (PST)
many many thanx Tom

I will check it out.

you are right

column username is unique and duplicate is not allowed

but if this is so why it is not redirecting the user

b/c when I first do it , it was working fine.

and redirecting showing error message that someone

else has got the login id



regards

nusrat







__________________________________________________

Do You Yahoo!?

Send your FREE holiday greetings online!

http://greetings.yahoo.com

Message #4 by "TomMallard" <mallard@s...> on Fri, 21 Dec 2001 15:02:17 -0800
This looks funny...



> Do While Not (objRS.EOF OR duplicate)

>  If duplicate=true  then

> response.redirect "newuser.asp?error=2"

>

> End If

> objRS.MoveNext

> Loop



I'd probably write that one like this...



Do while ((not objRS.EOF) or (duplicate = false))



as it's written, not certain how duplicate will resolve.



tom

> ----- Original Message -----

> From: "nusrat sarwar" <nusratsarwar@y...>

> To: "ASP Web HowTo" <asp_web_howto@p...>

> Sent: Friday, December 21, 2001 12:51 PM

> Subject: [asp_web_howto] Re: help

> 

> 

> > many many thanx Tom

> > I will check it out.

> > you are right

> > column username is unique and duplicate is not allowed

> > but if this is so why it is not redirecting the user

> > b/c when I first do it , it was working fine.

> > and redirecting showing error message that someone

> > else has got the login id

> >

> > regards

> > nusrat

> >

> >

> >

> > __________________________________________________

> > Do You Yahoo!?

> > Send your FREE holiday greetings online!

> > http://greetings.yahoo.com

> >




> $subst('Email.Unsub').

> >

> 



Message #5 by "Ken Schaefer" <ken@a...> on Sat, 22 Dec 2001 19:11:25 +1100
ARGH! Don't loop through the ENTIRE table looking for a duplicate. Construct

an SQL statement that will search for a matching record. If the Recordset is

.EOF then there is no match:



<%

strSQL = _

    "SELECT UserID " & _

    "FROM [Users] " & _

    "WHERE [Username] = '" & strUserName & "' " & _

    "AND [Pasword] = '" & strUserPassword & "'"



objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText



If objRS.EOF then

    ' User doesn't exist

    ' Add them now

    strRedirectURL = "welcome.asp"

Else

   ' User already exists

    strRedirectURL = "error.asp"

End If



objRS.close

Set objRS = Nothing

objConn.Close

Set objConn = Nothing



Response.Redirect(strRedirectURL)

%>



This is *MUCH* less load on your database since you are not returning the

*entire* table and searching through it one record at a time. Remember

databases work on *sets* not *cursors*. Avoid using cursors if at all

possible - return a relevant set instead.



Cheers

Ken



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From: "nusrat sarwar" <nusratsarwar@y...>

Subject: [asp_web_howto] help





: hello all!

: I am getting this error

: although data is being inserted even with this error.

: I wanna redirect the user but desired function is not

: performing

:

: Error Type:

: Microsoft OLE DB Provider for ODBC Drivers

: (0x80040E14)

: [Microsoft][ODBC Microsoft Access Driver] The changes

: you requested to the table were not successful because

: they would create duplicate values in the index,

: primary key, or relationship. Change the data in the

: field or fields that contain duplicate data, remove

: the index, or redefine the index to permit duplicate

: entries and try again.

: /baby/insertuser.asp, line 34

:

:

: Browser Type:

: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt

:

: where in my code I am wrong:

:

: <% @Language=VBScript%>

: <% Option Explicit %>

:

: <%

:

: Dim username, password, duplicate,strconn, objConn,

: objRS,SQL

: strconn = "DRIVER=Microsoft Access Driver

: (*.mdb);DBQ=" & Server.MapPath("/myfolder/mydb.mdb")

: set ObjConn=server.createobject("adodb.connection")

: ObjConn.open strconn

: username=trim(request.form("username"))

: password=trim(request.form("password"))

: duplicate=false

: If username = "" then

: response.redirect "newuser.asp?error=1"

: else

: If password = "" then

: response.redirect "newuser.asp?error=1"

: End If

: End If

: 'Now we create our recordset object that will create

: the user's record

: Set objRS = Server.CreateObject("ADODB.Recordset")

:

: objRS.Open "users", objConn , 2,2

:

: Do While Not (objRS.EOF OR duplicate)

:  If duplicate=true  then

: response.redirect "newuser.asp?error=2"

:

: End If

: objRS.MoveNext

: Loop

:

: SQL = "INSERT INTO users(username,password) VALUES

: ('"&username&"','"&password&"')"

: objConn.execute SQL

:

:

: objRS.Close

: Set objRS = nothing

: objConn.Close

: Set objConn = nothing

:

: Response.redirect "newuser.asp?success=1"

: %>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Message #6 by nusrat sarwar <nusratsarwar@y...> on Sun, 23 Dec 2001 11:31:23 -0800 (PST)
Tom and Ken Many thanx for yr expert advise.

I am obliged

regards.







__________________________________________________

Do You Yahoo!?

Send your FREE holiday greetings online!

http://greetings.yahoo.com


  Return to Index