Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2004, 04:22 PM
Authorized User
 
Join Date: Feb 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default error

I am trying to read the locatin of database from a file and 'am having the follwong error in it.
 ADODB.Connection (0x800A0E79). Operation is not allowed when the object is open.
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>




 
Old April 2nd, 2004, 11:57 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Question:

1. Do you store the name of the database or the path to the database in your textfile?

2. If you store only the name, then you will need to call Server.MapPath() to resolve the path on your server. If you store the full path, it must be a path on your server.

3. Why don't you use an Application variable for the database connection string and initialize it in global.asa? Then you would be able to keep the connection string in one location.

global.asa:

<%
Application("Database_Connection") = _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("YourDatabaseName.mdb")
%>

Then in your asp pages you can reference the connection string:

<%
'...
objConn.Open Application("Database_Connnection")
'...
%>


 
Old April 5th, 2004, 01:18 PM
Authorized User
 
Join Date: Feb 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks UNCLE for ur suggestion, but the code works fine if I only read a single database location from the text file am using. I think my problem is in my loop, and I cannot spot it out






Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
[Resolved] Error calling a sp - parameter error snufse .NET Framework 2.0 2 February 12th, 2008 04:46 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
Phile Page error, visual studio error reps BOOK: ASP.NET Website Programming Problem-Design-Solution 0 September 27th, 2003 10:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.