By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

Query timeout expired when doing update to password to a field

P: 2
Hi all,

Does anyone have an idea to solve this problem in asp? I have tried to look everywhere for the last week but no one seems to have the answer.

The issue is that I have the script below that is used to generate new password which is the encripted to update the password field in the database. It then suprisingly times out when used with sql server and the field is not updated, however, if you use the access database, the password field is updated and the new password is sent to the user.

Which means that the issue could be on the rs handling and sql...

Please help, or advice...

Cheers,

Erick

Expand|Select|Wrap|Line Numbers
  1.  <!--#include file="include/clean.asp"-->
  2. <!--#include file="include/dbcommon.asp"-->
  3. <!--#include file="include/md5.asp"-->
  4. <!--#include file="libs/xtempl.asp"-->
  5. <%
  6. if SESSION("count_captcha")="" or SESSION("count_captcha")>5 then SESSION("count_captcha")=0
  7.  
  8. dim xt
  9. set xt = new XTempl
  10. cEmailField = "Email (mail)"
  11. reminded=false
  12. strSearchBy="username"
  13.  
  14. strUsername=""
  15. strEmail=""
  16. strMessage=""
  17.  
  18. dbConnection=""
  19. db_connect()
  20. DoEvent "BeforeProcessRemind dbConnection"
  21.  
  22.  
  23. if request.form("btnSubmit") = "Remind" then
  24.     strSearchBy=request.Form("searchby")
  25.     'strUsername=request.Form("username")
  26.     strUsername = cleanName(request.Form("username"))
  27.     strEmail=request.Form("email")
  28.        Set rstemp = server.CreateObject("ADODB.Recordset")
  29.        Set rs = server.CreateObject("ADODB.Recordset")
  30.  
  31.     rstemp.open "select * from [Staff Details] where 1=0",dbConnection,1,2
  32.  
  33.     tosearch=false
  34.     if strSearchBy<>"email" then
  35.         value=strUsername
  36.         if cstr(value)<>"" then tosearch=true
  37.         if FieldNeedQuotes(rstemp,cUserNameField) then 
  38.             value="'" & db_addslashes(value) & "'"
  39.         else
  40.             value=my_numeric(value)
  41.         end if
  42.         sWhere=AddFieldWrappers(cUserNameField) & "=" & value
  43.     else
  44.         value=strEmail
  45.         if cstr(value)<>"" then tosearch=true
  46.         if FieldNeedQuotes(rstemp,cEmailField) then
  47.             value="'" & db_addslashes(value) & "'"
  48.         else
  49.             value=my_numeric(value)
  50.         end if
  51.         sWhere=AddFieldWrappers(cEmailField) & "=" & value
  52.     end if
  53.  
  54.     if tosearch then DoEvent "tosearch = BeforeRemindPassword(strUsername,strEmail)"
  55.  
  56.  
  57.     if tosearch then
  58.  
  59.         strSQL="select " & AddFieldWrappers(cUserNameField) & "," & AddFieldWrappers(cPasswordField) & "," & AddFieldWrappers(cEmailField) & " from [Staff Details] where " & sWhere
  60.         rs.Open strSQL,dbConnection,1,2
  61.         'set rs = server.createobject("adodb.recordset")
  62.         'rs.open strSQL, dbConnection,1,2
  63.         if not rs.EOF then
  64.             password=rs(1)
  65. '//    generate 6 letters length password
  66.             password=""
  67.             randomize
  68.             for ind=0 to 5
  69.                 j=rnd(35)
  70.                 if j<26 then
  71.                     password=password & chr(asc("a")+j)
  72.                 else
  73.                     password=password & chr(asc("0")-26+j)
  74.                 end if
  75.  
  76.             next
  77.             dbConnection.Execute "update [Staff Details] set " & AddFieldWrappers(cPasswordField) & "='" & md5(password) & "' where " & sWhere
  78.             'response.Write(password)
  79.             'response.End()
  80.             'j
  81.             url = "http://" & request.ServerVariables("SERVER_NAME")
  82.             if CStr(request.ServerVariables("SERVER_PORT"))<>"80" then _
  83.                 url = url & ":" & request.ServerVariables("SERVER_PORT")
  84.             url= url & request.ServerVariables("SCRIPT_NAME")
  85.             message="Password reminder" & vbcrlf
  86.             message=message & "You asked to remind your username and password at" & " " & url & vbcrlf
  87.             message=message & "Username" & " " & rs(0) & vbcrlf
  88.             message=message & "Password" & " " & password & vbcrlf
  89.             sendmail rs(2),"Password reminder",message
  90.             reminded=true
  91.             DoEvent "AfterRemindPassword strUsername,strEmail"
  92.             loginlink_attrs="href=""login.asp"
  93.             if strSearchBy<>"email" then loginlink_attrs=loginlink_attrs & "?username=" & server.HTMLEncode(strUsername)
  94.             loginlink_attrs=loginlink_attrs & """"
  95.             xt.assign "loginlink_attrs",loginlink_attrs
  96.             xt.assign "body",true
  97.             SESSION("count_captcha")=SESSION("count_captcha")+1
  98.             xt.display("remind_success.htm")
  99.             response.End
  100.         end if
  101.     end if
  102.  
  103.     if not reminded then
  104.         if strSearchBy<>"email" then
  105.             strMessage="User" & " <i>" & strUsername & "</i> " & "is not registered."
  106.         else
  107.             strMessage="This email doesn't exist in our database"
  108.         end if
  109.     end if
  110.  
  111. end if
  112.  
  113. emailradio_attrs="onclick=""document.forms.form1.searchby.value='email'; UpdateControls();"""
  114. usernameradio_attrs="onclick=""document.forms.form1.searchby.value='username'; UpdateControls();"""
  115.  
  116. if strSearchBy="username" then
  117.     usernameradio_attrs=usernameradio_attrs & " checked"
  118.     search_disabled = "email"
  119. end if
  120.  
  121. xt.assign "emailradio_attrs",emailradio_attrs
  122. xt.assign "usernameradio_attrs",usernameradio_attrs
  123.  
  124. xt.assign "username_attrs","value=""" & my_htmlspecialchars(strUsername) & """"
  125. xt.assign "email_attrs","value=""" & my_htmlspecialchars(strEmail) & """"
  126. if strMessage<>"" then
  127.     xt.assign "message",strMessage
  128.     xt.assign "message_block",true
  129.     if captcha=1 then SESSION("count_captcha")=SESSION("count_captcha")+1
  130. end if
  131.  
  132. set body=CreateObject("Scripting.Dictionary")
  133. str="<script language = JavaScript>"
  134. str=str & "function OnKeyDown(){"
  135. str=str & "e = window.event;"
  136. str=str & "if (e.keyCode == 13){"
  137. str=str & "e.cancel = true;"
  138. str=str & "document.forms[0].submit();}}"
  139. str=str & "function UpdateControls(){"
  140. str=str & "if (document.forms.form1.searchby.value==""username""){"
  141. str=str & "document.forms.form1.username.style.backgroundColor='white';"
  142. str=str & "document.forms.form1.email.style.backgroundColor='gainsboro';"
  143. str=str & "document.forms.form1.username.disabled=false;"
  144. str=str & "document.forms.form1.email.disabled=true;}else{"
  145. str=str & "document.forms.form1.username.style.backgroundColor='gainsboro';"
  146. str=str & "document.forms.form1.email.style.backgroundColor='white';"
  147. str=str & "document.forms.form1.username.disabled=true;"
  148. str=str & "document.forms.form1.email.disabled=false;}}</script>"
  149. str=str & "<form method=post action=""remind.asp"" id=form1 name=form1>"
  150. str=str & "<input type=hidden name=btnSubmit value=""Remind"">"
  151. str=str & "<input type=""Hidden"" name=""searchby"" value=""" & strSearchBy & """>"
  152. body("begin")=str
  153. body("end")="</form><script language=""JavaScript"">document.forms.form1." & search_disabled & ".disabled=false;    UpdateControls();</script>"
  154. xt.assign "body",body
  155.  
  156.  
  157. templatefile = "remind.htm"
  158. DoEvent "BeforeShowRemindPwd xt,templatefile"
  159. xt.display(templatefile)
  160. %> 
Apr 25 '11 #1
Share this Question
Share on Google+
2 Replies


jhardman
Expert 2.5K+
P: 3,405
just some basic troubleshooting steps:

Can you query or execute a static command to your sql server? in other words, does "select * from [Staff Details]" work? Does a static update command like "update [staff Details] set pword = 'asdf1' where idnum=3" work?

Jared
Apr 25 '11 #2

P: 2
Dear Jared,

thanks for the reply, I have queried this
Expand|Select|Wrap|Line Numbers
  1. update [Staff Details] set [password]='MD5 hash value' where [username]='admin'
which is generated when I did response write in the sql server but yes it is indicating that it is executed but when you use the password which was sent after the generated one it still seems the field was not updated.

There is no error though which is generated, so I still do not understand why the password field does not update with the new encrypted one. The sql query indicates "Query successfully executed" and one "rows affected".

Also, I have tried "select * from [Staff Details]" query and it works pretty well returning all the values in the table

Thanks in advance

Erick
Apr 26 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.