Connecting Tech Pros Worldwide Forums | Help | Site Map

Please need help with this error... Urgent

Newbie
 
Join Date: Sep 2008
Posts: 2
#1: Sep 12 '08
I am a .NET programmer and i had recently got a web application designed in Classic ASP, to make some modifications.

When i run the application and try to create a new user the following error pops up. "The email address you entered already exists."

Now my problem is i am not able to find out the where the error is generating or why as the datdabase table is completely empty (no records)

Below is the code...
++++++++++++++++++
Expand|Select|Wrap|Line Numbers
  1.  <%
  2. Dim action 'After validations the request is sent to here with action value as 1
  3. action = Request.QueryString("action")
  4.  
  5. Select Case (action)
  6. Case "1"
  7.     Dim objConnection, objRecordset, SQLs, strUserID
  8.     Dim strPassword, strFname, strLname, strAddress,  strCity, strCountry
  9.     Dim strZip, strUserType, strJoinDate, strEducation, strNewsletter, strEmail, strCareer
  10.  
  11.     Set objConnection = Server.CreateObject("ADODB.Connection")
  12.     Set objRecordset = Server.CreateObject("ADODB.Recordset")
  13.     objConnection.Open Application("ConnectionString")
  14.  
  15.     strUserType= 0
  16.  
  17.     strFname=Replace((Request.Form("firstname")),"'", "")
  18.     strLname=Replace((Request.Form("lastname")),"'", "")
  19.     strAddress=Replace((Request.Form("address")),"'", "")
  20.     strCity=Replace((Request.Form("city")),"'", "")
  21.     strZip=Replace((Request.Form("zip")),"'", "")
  22.     strCountry=Replace((Request.Form("country")),"'", "")
  23.     strEmail=Replace((Request.Form("emailaddress")),"'", "")
  24.     strPassword=Replace((Request.Form("password")),"'", "")
  25.     strCareer=Replace((Request.Form("careerlevel")),"'", "")
  26.     strEducation=Replace((Request.Form("education")),"'", "")
  27.     strJoinDate=(Request.Form("joindate"))
  28.     strNewsletter=(CInt(Request.Form("newsletter")))
  29.  
  30.     If strNewsletter <> 1 Then
  31.         strNewletter = 0
  32.         End If
  33. ' ## ERROR CONTROL ##
  34.     objConnection.Errors.Clear 
  35.     On Error Resume Next
  36.     SQLs = "INSERT INTO Users (Email, Fname, Lname, UsrPassword, Address, City, Country, Zip, " & _
  37.     "CareerLevel, Education, JoinDate, " &_
  38.     "Newsletter, UserType) "
  39.     SQLs = SQLs & "VALUES ("
  40.     SQLs = SQLs & "'" & strEmail & "'," 
  41.     SQLs = SQLs & " '" & strFname & "'," 
  42.     SQLs = SQLs & " '" & strLname & "'," 
  43.     SQLs = SQLs & " '" & strPassword & "'," 
  44.     SQLs = SQLs & " '" & strAddress & "'," 
  45.     SQLs = SQLs & " '" & strCity & "'," 
  46.     SQLs = SQLs & " " & strCountry & "," 
  47.     SQLs = SQLs & " '" & strZip & "'," 
  48.     SQLs = SQLs & " '" & strCareer & "'," 
  49.     SQLs = SQLs & " '" & strEducation & "'," 
  50.     SQLs = SQLs & " '" & strJoinDate & "'," 
  51.     SQLs = SQLs & " '" & strNewsletter & "'," 
  52.     SQLs = SQLs & " " & strUserType & ")"
  53.  
  54.     Application.Lock
  55.     objConnection.Execute(SQLs) 'Expected Error    
  56. Application.Unlock
  57.  
  58. ' ## ERROR CONTROL ##
  59. On Error GoTo 0 
  60. For Each oops In objConnection.Errors
  61.  
  62.     If oops.number = -2147467259 Then
  63.     Session("Session_Message") = "The email address you entered already exists. <br />" & _
  64.         "<a href=""/jobs/forgotpass.asp"">Forgot password? Click here</a>" '& oops.description Error Message
  65.        Dim strQueryString
  66.        strQueryString = "?firstname=" & strFname & "&lastname=" & strLname & "&address=" & strAddress & _
  67.            "&city=" & strCity & "&zip=" & strZip & "&emailaddress=" & strEmail 
  68.  
  69.        Response.Redirect("/jobs/candidate/contactinfo.asp" & strQueryString)
  70.         Response.End()
  71.     Else
  72.         Response.Write "Unexpected error: " & oops.number & " -- " & oops.description & SQLs
  73.  
  74.         Response.End()
  75.     End If
  76. Next
  77.  
  78.  
  79.  
  80. Set objRecordset = objConnection.Execute("SELECT @@IDENTITY") 
  81. strUserID = objRecordset(0)         
  82. objConnection.Close
  83.  Set objRecordset = Nothing
  84.  
  85. LoginUser (strUserID)    
  86.  
  87.  Session("Session_Message") = "Welcome " &  Session("User_Name")
  88.  
  89.         If Session("UserLoggedIn") = true Then
  90.         Response.Redirect("/jobs/candidate/default.asp")
  91.         End If
  92.  
++++++++++++++++++
Points in bold are for easy identification please ignore them...

I am sure on the working and no idea what does the error number (-2147467259) represents.

Please help me in this regard.
Thank You...

jeffstl's Avatar
Expert
 
Join Date: Feb 2008
Posts: 414
#2: Sep 12 '08

re: Please need help with this error... Urgent


The logic of the code is flawed.

If the database is returning -2147467259 that does not necessarily mean a unique key violation. It could mean any number of things.

Google Search

So the first thing you should do is figure out why the database is returning that. My guess is that either you have the database open exclusively (if its Access) or you have some kind of other connectivity issue if its another database type.
Newbie
 
Join Date: Sep 2008
Posts: 3
#3: Sep 15 '08

re: Please need help with this error... Urgent


i am new with ASP and i really wish i could help..seeing your codes put smiles on my face like am the one writing it..i don't know if u can help me out with the ASP.NET commands and their meaning..thanx alot
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#4: Sep 15 '08

re: Please need help with this error... Urgent


Jeff is right. I would suggest you start by commenting out the "on error resume next" line, so you can see what the actual error is and what line is throwing it.

Jared
Reply