1

Context:

I have an update query for a Microsoft Access DB that keeps failing. The query works when executed from within my DB, but fails when executed from my CodeFile for my .aspx page.

I have ensured that:

  • My App_Data folder has write permissions (via IUSR)
  • My DB is not 'Read Only'
  • My query syntax is correct

Does anyone have any advice on what I might be missing? Thank you!!

Code:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Imports System.Data.OleDb

Partial Class jsDB

Inherits System.Web.UI.Page

Private con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\Dustin\App_Data\FAQ.accdb")

Public Sub Page_Load(sender as object, e as System.EventArgs)

    If request.QueryString("type") = "helpful" Then

        Dim cleanID as string
        cleanID = request.querystring("id")

        If IsNumeric(cint(cleanID)) Then 'Make sure QueryString hasn't been tampered with

            Dim sql as string
            sql = "UPDATE QUESTION SET helpful=helpful+1 WHERE questionID=" & cleanID

            Dim cmd As New OleDbCommand(sql, con)

            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()

            Response.write("Success")

        else

            Response.write("Invalid ID")

        end if

    else

        Response.write("No recognized type")

    end If

End Sub
End Class

Error:

Server Error in '/' Application.

Operation must use an updateable query. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.

Source Error:
Line 27:
Line 28: con.Open()
Line 29: cmd.ExecuteNonQuery()
Line 30: con.Close()
Line 31:
Source File: C:\Dustin\FAQDB.aspx.vb Line: 29

Stack Trace:
[OleDbException (0x80004005): Operation must use an updateable query.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1102900 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +189 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +162 System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +107 jsDB.Page_Load(Object sender, EventArgs e) in C:\Dustin\FAQDB.aspx.vb:29 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +92 System.Web.UI.Control.LoadRecursive() +54 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

  • What is the user reported by the Environement.UserName just before executing the query? http://www.codeproject.com/Questions/442585/operation-must-use-an-updateable-query-ms-access – Steve Nov 12 '15 at 18:39
  • I can't say with authority if the error message means the same thing (it's a vague message), but this might help: http://stackoverflow.com/questions/24798509/system-data-oledb-oledbexception-operation-must-use-an-updateable-query – David Nov 12 '15 at 18:39
  • @Steve Environment.UserName = DefaultAppPool. Is this a red flag? I'm not familiar with user settings for IIS, but can most certainly go down this rabbit hole if its most likely the cause. – Uncle Bojangles Nov 12 '15 at 18:54
  • Perhaps, read http://www.iis.net/learn/manage/configuring-security/application-pool-identities – Steve Nov 12 '15 at 18:57

3 Answers3

0

This help page addresses the error you are receiving:

https://support.microsoft.com/en-us/kb/175168

It looks like either youre not opening the connection in the right mode (Mode 3 in this case) or the "table" you are updating has conditions which prevent you from updating it. I'd bet though that changing your Mode to 3 will resolve the issue.

Unicorno Marley
  • 1,744
  • 1
  • 14
  • 17
  • Unless I'm misunderstanding something, there is no Mode property for an OLEDB connection. Forgive me if I'm mistaken! I see no equivalent for the OleDbConnection class. – Uncle Bojangles Nov 12 '15 at 19:24
0

There are several things done wrong here that may help you resolve this and other issues in the future.

  1. IsNumeric(cint(cleanID)) - The IsNumeric() on CInt() is irrelevant. The CInt will either return a System.Int32 or an error. You should just do the IsNumeric() and if you want to know if it is an Int32, then do a Int32.TryParse() on it.
  2. Your command should be parameterized to avoid injection and to avoid passing the wrong data type. For example, I don't know if questionID is a string (which makes your syntax wrong) or if it is an int32. But, a parameterized command would and will supply the correct syntax to your SQL. You can find thousands of example on ho to do this so I will not explain it again here.
  3. The last item, and likely the solution, MS Access queries like to end in a semicolon (;). Seems like I have had issues in the past with not having them in my UPDATE commands for MS Access.

As a side-note. MS Access is terrible about handling multiple connections so leaving them open because of errors will cause you HUGE problems. Be sure that all database calls have proper error handling and if you can put them in a USING block, even better.

Steve
  • 5,585
  • 2
  • 18
  • 32
  • I've made all of your recommended changes (thank you for the amazing feedback ), but I'm still getting an error. My catch statement is reporting the following exception message: "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine." Does this mean I need to have our tech team load a driver to our webserver? Thank you so much for your help thus far, by the way!! – Uncle Bojangles Nov 12 '15 at 19:50
  • Your error on the web server is a WHOLE other issue. I wont answer that here but I will give you a hint (since I already know this one too); the ACE driver is not installed with the OS on x64 servers like they ALWAYS have been. – Steve Nov 12 '15 at 21:53
  • Yup I managed to figure this out a little after I posted the new exception. Going to update my post with the answer. Thanks for your help! – Uncle Bojangles Nov 12 '15 at 21:56
0

Shout-out to @Steve for being such a big help on this.

I had several issues here. While I'm sure there are many issues which could produce the error I was experiencing, here's what resolved it for me:

  • Created a new application pool in IIS and gave this new pool write permissions to my App_Data folder
  • Assigned this new app pool to my application
  • Modified the new app pool under advanced settings to allow 32 bit applications

As of right now, the 'Microsoft.ACE.OLEDB.12.0' provider only works as 32-bit. Changing my application pool to allow 32 bit applications resolved the issue.

Thanks all for your input!