Problem with database opening
I am trying to read the location of database from a file and 'am having the follwong error in it.
ADODB.Connection (0x800A0E79). Operation is not allowed when the object is opened.
Here's my code:
<% Response.Buffer = true %>
<html>
<head>
<Title>Passoword change website</title>
</head>
<body>
<h2>Password change response<h2>
<%
'Declare variable needed
Dim strSql
Dim adCmdText
Dim varTable
Dim varDatabase
adCmdText = 1
'Retrieve the values
varStudentID = Request.Form("StudentId")
varPassword = Request.Form("Password")
varNewpassword = Request.Form("NewPassword")
varTable = "Try"
'varDatabase = "new1"
'start building sql statement
strSql = "Update " & varTable & " Set"
strSql = strSql & " Password ='" & varNewpassword & "'"
strSql = strSql & " WHERE StudentID =" & varStudentID
strSql = strSql & " AND Password='" & varPassword & "'"
'Create and open File object for reading file database name and location
Set objFile1 = Server.CreateObject("Scripting.FileSystemObject")
Set objData = objFile1.OpenTextFile(Server.MapPath("Database.txt "),1,False)
'Create connection to database
Set objConn = Server.CreateObject("ADODB.Connection")
' Read the names of the database from the file and update the databases
'Create and open File object for a log
Set objFile = Server.CreateObject("Scripting.FileSystemObject")
Set objLog = objFile.OpenTextFile(Server.MapPath("LoginLog.txt" ),8,True)
'Check if the user entered a valid username and password.
Function validation(objconn, varStudentID, varPassword)
set objRS=Server.CreateObject("ADODB.Recordset")
stSql = "Select * FROM " & varTable
stSql = stSql & " WHERE StudentID =" & varStudentID
stSql = stSql & " AND Password='" & varPassword & "'"
objRS.Open stSql, objConn
If objRS.EOF or objRS.BOF Then
Validation = "true"
else
Validation = "false"
End if
objRS.close
Set objRS = Nothing
End Function
Sub Update(objconn, varStudentID, varPassword, strSql)
'Create command object
Set objCmd = Server.CreateObject("ADODB.Command")
'Set Command Properties
Set objCmd.ActiveConnection = objConn
objCmd.CommandText = strSql
objCmd.CommandType = adCmdText
'Execute Command
objCmd.Execute
Response.Write "You have successfuly changed your password"
Set objCmd = Nothing
End Sub
Sub Action_Option(validate, objLog, objconn, varStudentID, varPassword, strSql)
if Validate="true" then
'Write into log file to indicate that attempt to change password failed
'and Redirect the user back to the log in page
objLog.WriteLine(varStudentID & " " & "Failed" & " " & Date & " " & Time)
Response.Write "Incorrect Username or password please try again"
Response.Redirect "New2201.asp"
Response.Clear
Else
'update the currrent database and wite log to the the file.
objLog.WriteLine(varStudentID & " " & "Successfull" & " " & Date & " " & Time)
call Update(objconn, varStudentID, varPassword, strSql)
End If
End Sub
Do While objdata.AtEndOfStream <> True
'Read from the File
varDatabase = objData.ReadLine
'Open the database read from the text file
objConn.OPen "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & varDatabase
'validate the input the password and the userid
validate = validation(objconn, varStudentID, varPassword)
'Call the update or redirect the user depending on the value of validate
call Action_Option(validate, objLog, objconn, varStudentID, varPassword, strSql)
Loop
'Response.Write " Your passwords has been changed."
'Response.write " The number of record that has changed is: " & _
' intnumofrecord & " records<BR><BR>"
objData.Close
Set objData = nothing
set objFile1 = nothing
objLog.Close
Set objLog = nothing
Set objFile = nothing
objConn.Close
Set objConn = Nothing
%>
</body>
</html>
|