Dreamweaver CS5 사용 다음과 같은 서버 동작을 추가했습니다.ASP Classic에서 중첩 MSSQL 업데이트 명령을 닫아야합니까?
질문 : MM_rsUser1을 닫아야합니까?
자동 생성 된 코드는 MM_rsUser를 닫지 만 MM_rsUser가 닫히기 전이나 후에 줄의 MM_rsUser1을 닫으려고하면 페이지가 실패합니다.
내가 '필요 없다'는 것을 나타내는 것으로 보이는이 reference for MySql이 첫 번째 프로젝트이므로 가능한 한 많은 '좋은 습관'을 배우려고 노력하고 있으며 Dreamweaver가 많이 생성하고 있기 때문에 VB 코드 중, 나는 그것이 나를 위해하는 일이 필연적으로 오늘날 가장 좋은 방법이라고 가정하고 싶지 않습니다. 처음에,
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("userid"))
If MM_valUsername <> "" Then
Dim MM_fldUserAuthorization
Dim MM_redirectLoginSuccess
Dim MM_redirectLoginFailed
Dim MM_loginSQL
Dim MM_rsUser
Dim MM_rsUser_cmd
Dim MM_loginUpdate ' used to execute timestamp to log last successful login for user
Dim MM_rsUser1 ' also used to execute timestamp as above
MM_fldUserAuthorization = "accessLevel"
MM_redirectLoginSuccess = "/sql.asp"
MM_redirectLoginFailed = "/login.asp"
MM_loginSQL = "SELECT email, password"
If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
MM_loginSQL = MM_loginSQL & " FROM table WHERE userid = ? AND pword = ?"
Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
MM_rsUser_cmd.ActiveConnection = MM_SQL_STRING
MM_rsUser_cmd.CommandText = MM_loginSQL
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 202, 1, 50, MM_valUsername) ' adVarWChar
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 202, 1, 50, Request.Form("password")) ' adVarWChar
MM_rsUser_cmd.Prepared = true
Set MM_rsUser = MM_rsUser_cmd.Execute
If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' username and password match - this is a valid user
Session("MM_Username") = MM_valUsername
MM_loginUpdate = "UPDATE table SET lastLoggedIn = { fn NOW() } WHERE userid = '" & MM_valUsername & "'"
MM_rsUser_cmd.CommandText = MM_loginUpdate
Set MM_rsUser1 = MM_rsUser_cmd.Execute ' unsure if I have to write an MM_rsUser1.Close somewhere or not, but page fails where I've tried
If (MM_fldUserAuthorization <> "") Then
Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
Else
Session("MM_UserAuthorization") = ""
End If
if CStr(Request.QueryString("accessdenied")) <> "" And true Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
감사를 변경합니다. 불행히도, 나는 당신이 제안한 장소에서 그것을 닫으려고했습니다. (제 첫 질문에서 분명하지 않은 것에 대해 유감스럽게 생각합니다 ... MM_rsUser도 더 아래로 닫혔습니다). 다른 의견은 있습니까? –
+1 좋은 습관을 배우고 MVC/C#으로 이동할 계획이었습니다. "페이지가 실패합니다."라는 내용을 모른 채 제안 할 수있는 것은 많지 않습니다. 다음 3 가지 경우 모두 테스트해야합니다. (1) 입력 된 사용자 ID가 없습니다. (2) 사용자 ID (MM_valUsername) 및 암호는 입력되었지만 조회에서 찾을 수 없습니다. (3) 좋은 사용자 ID 및 암호. 그리고 나는 우스꽝스럽게 냄새를 맡는 또 하나의 것을 본다. 나는 나의 대답을 업데이트 할 것이다. –
나는 기본적으로 MM_rsUser에 대한 코드의 첫 번째 배치를 복사/붙여 넣기하여 기본적으로 제안한 것과 비슷한 작업을 시도했지만 페이지가 전혀로드되지 않습니다. MM_reUser_cmd.Execute를 '재사용'하는 과정에서 생각한 것은 위에서 언급 한 두 줄을 업데이트에 배치 한 시점에서 연결이 이미 열려 있고 이미 첫 번째 SQL 문을 처리했기 때문에 ' 그 문장을 MM_LoginSQL에서 MM_loginUpdate로 변경하여 재사용 할 수 있습니다. 앞에 올 때 올바른 사용자/암호를 사용한 후에 만 페이지가 실패 함 If (MM_fldUserAuthorization <> "") –