Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 19th, 2004, 01:54 PM
Authorized User
Join Date: Feb 2004
Location: marshall, MN, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 %>

<Title>Passoword change website</title>
<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"
        Validation = "false"
    End if
    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
        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"

          '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)

'Response.Write " Your passwords has been changed."
'Response.write " The number of record that has changed is: " & _
' intnumofrecord & " records<BR><BR>"

Set objData = nothing
set objFile1 = nothing
Set objLog = nothing
Set objFile = nothing
Set objConn = Nothing



Reply With Quote
  #2 (permalink)  
Old April 23rd, 2004, 10:59 AM
Friend of Wrox
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post

Put this Outside the DO WHILE... LOOP. But you may get other errors.

objConn.OPen "Driver={Microsoft Access Driver (*.mdb)};" & _
         "DBQ=" & varDatabase

Hope that helps!

-Vijay G
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 11 - Problem Opening Database dbcook8 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 15 February 2nd, 2009 08:41 AM
Opening One Database from another Brendan Bartley Access 19 August 22nd, 2007 04:03 AM
Problems opening MS Access database JayM ASP.NET 2.0 Basics 1 June 5th, 2006 01:59 PM
Database Error message when opening Brendan Bartley Access 1 July 19th, 2005 12:26 PM
Problem in opening a VSS database on remote m/c nikunjn VS.NET 2002/2003 5 July 22nd, 2004 08:57 PM

All times are GMT -4. The time now is 09:14 AM.

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