Writing to Access using IIS and ASP/PHP

  • 19 years ago

    I am running Microsoft Windows XP Professional and IIS 5.1


    I am making a messageboard application in ASP but when I connect to the Access 2000 database (without a DSN) i get the following error:


    [Microsoft][ODBC Microsoft Access Driver] Cannot update. Database or object is read-only.


    I am absolutely 101% sure that the code is correct, as I've looked in serveral books and online tutorials, and even downloaded and run examples, and they all give this or a similar error. The .mdb file on my hard disk is NOT, repeat NOT read-only. I feel sure that there must be some permission setting somewhere which is stopping me write to the database. I can extract data from it without any difficulty at all!


    I'd be really grateful to anybody that can help me.

  • 19 years ago

    You need to grant write access for IUSR_MACHINENAME to the access database file

  • 19 years ago

    Hello there.


    I'm afraid I'm relatively new to ASP and PHP database applications, would it be possible for some instructions as to how I should do that? Thanks very much.

  • 19 years ago

    Go into Explorer. Select the *.mdb file. On the security tab, click Add... Select IUSR_MACHINENAME where MACHINENAME is the name of your PC. Click OK, and then check the box next to read and write in the permissions dialog. Click OK... that should do the trick. You may also need to do the same thing with the whole folder.

  • 19 years ago

    Hi there and thanks very much for your help - it's very much appreciated.


    I wasn't able to follow your instructions exactly, I think this is because of it being XP not 9x. The folder in which the *.mdb file is in has Write access enabled anyway (in the virtual folder in IIS and in the Web Sharing tab of the folder properties).


    However, I think I've discovered why it thought it was read-only, it was because it was done in a previous version of Access (I have 2k). I have now converted it and the error message is:


    >>>>>Operation is not allowed when the object is closed.<<<<<


    As I said, the source IS correct, as it's en example from an ASP book CD-ROM that I'm trying to do, and I've pulled lots of ASPs and PHPs off the net trying to do this, and they all give this error.


    I'd be really grateful if you could offer some further advice.


    Once again, thank you very much.

  • 19 years ago

    On win9x, the permissions problem wouldn't occur anyway


    Anyhow, by the looks of the new error message, the source code  you have either is incorrect (you'd be surprised how many errors creep into these books), or you've missed out some earlier code to open the connection object or something. Could you post all the code you are using?

  • 19 years ago

    Hello and thank you once again for your wonderful help; I really appreciate it


    This the relevant part from placead.asp from the ASP For Dummies CD-ROM:


    Set Connect = Server.CreateObject("ADODB.Connection")
    Connect.Open "ClassDSN"


    Set Classifieds = Server.CreateObject("ADODB.Recordset")
    Classifieds.Open _
      "SELECT * FROM Items WHERE Category='" & _
      Request("Category") & "'",_
      Connect,adOpenDynamic,adLockOptimistic
    Classifieds.AddNew
    Classifieds("Item") = Request("Item")
    Classifieds("Category") = Request("Category")
    Classifieds("Description") = Request("Description")
    Classifieds("Price") = Request("Price")
    Classifieds("Phone") = Request("Phone")
    Classifieds("Email") = Request("Email")
    Classifieds("State") = Request("State")
    Classifieds("Posted") = Date
    Classifieds("Password") = Request("Password")
    Classifieds.Update


    This uses a system DSN which is set up properly, and gives this:
    Operation is not allowed when the object is closed.


    I have also tried the following to do it without using a DSN:


    ' construct path...
    path = Request.ServerVariables("Path_Translated")
    path = Left(path,InStrRev(path,"\")) & "classdb.mdb"


    ' Open Connection
    Set Connect = Server.CreateObject("ADODB.Connection")
    Connect.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & path


    ' Open recordset
    Set Classifieds = Server.CreateObject("ADODB.Recordset")
    Classifieds.Open ("SELECT * FROM Items WHERE Category='" & Request("Category") & "'"),_
       Connect,adOpenDynamic,adLockOptimistic


    Classifieds.AddNew
    Classifieds ("Item") = Request("Item")
    Classifieds ("Category") = Request("Category")
    Classifieds ("Description") = Request("Description")
    Classifieds ("Price") = Request("Price")
    Classifieds ("Phone") = Request("Phone")
    Classifieds ("Email") = Request("Email")
    Classifieds ("State") = Request("State")
    Classifieds ("Posted") = Date
    Classifieds ("Password") = Request("Password")
    Classifieds.Update


    This gives the error message:
    [Microsoft][ODBC Microsoft Access Driver] Cannot update. Database or object is read-only.
    ... so I think there must be something wrong in my amended code, am I opening the database object for read-only????


    Thanks very much

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” - Martin Fowler