Datase or object read only - Delete on a recordset - SQL Server linked table

Team -

Access 2003, SQL Server 2000

Problem Summary - Delete method on a recordset gives runtime error 3027 - Cannot update. Database or object is read-only.

Particulars
Database - Linked table, has primary key
User defined in System DSN
DSN uses SQL Server for authentification
User has Select, Update, Delete, Update permissions in SQL Server
Password prompted for on first access of SQL Server
Using DAO

Interesting note - a delete query defined in Queries on the same table works in the development environment.

Details -

The following code fails -

Private Sub deleteUserAccessUsingProjectIDs(removeIDs As Collection)
    Dim rs As Recordset
    Dim db As Database
    Dim varItem, rsItem As Variant
    Dim qry As QueryDef
   
    Set db = CurrentDb()
    Set qry = db.QueryDefs("UserAccessForLoginName")
    qry.Parameters(0).value = Me.OpenArgs
    Set rs = qry.OpenRecordset(openType, dbSeeChanges)

    If (rs.EOF) Then
        GoTo exit_deleteUserAccessUsingProjectIDs
    End If
    For Each varItem In removeIDs
        rs.MoveFirst
        Do While Not rs.EOF
            If rs("txpi_ID") = varItem Then
                  rs.Delete '***FAILS HERE***
             End If
            rs.MoveNext
        Loop
    Next

exit_deleteUserAccessUsingProjectIDs:
    rs.Close
    Set rs = Nothing
End Sub


===============================

I hope someone can help!
Brad Cote
blcoteAsked:
Who is Participating?
 
harfangCommented:
Hello blcote

I don't have Access 2003 here, but the parameter "openType" looks strange. What is its value? It's not an intrinsic constant, nor is it defined in the Sub. Is it a global constant?

If none of these apply, does your module contain the line "Option Explicit" at the top, and does it compile? (menu "debug / compile <project>")

Anyway, you might want to try dbOpenDynaset instead. By the way, dbSeeChanges seems to apply to Jet databases only, I don't think it would have any effect here.

You can trap the error like this:

    If Not rs.Updatable Then MsgBox "recordset not updatable"   ' DAO
    If Not rs.Supports(adDelete) Then MsgBox "can't delete"   ' ADODB

If all this fails, you can try using ADO recordsets instead. They are normally better suited  with operations on SQL Server data.

Finally, and since the queries work, you can run delete  queries instead of deleting from the recordset... On the other hand, if your keep the recordset solution, you should probably use the .FindFirst or .Find methods instead of looping through the entire recordset each time...

(°v°)
0
 
Kelvin SparksCommented:
I tend to agree with Harfang's comments except that the dbSeeChanges constant is needed on all querydef and recordset operations where DAO is used via a dsn connection - they fail horribly without.

I tend to try and replace all recordsets used in this DAO/dsn environment. Theyare much slower than when used over Access linked tables. I try and replace with a batch query, or if possible redevelop that functionality into a stored procedure on the server and fire using a pass through query
0
 
blcoteAuthor Commented:
Team -

Sorry about dbType - it is dbOpenDynaset in the actual call (I had a function to return the recordset, pasing in the openType arg so it could be opened as read only also. I tried to simplify the example by taking out the function call).

kelvinsparks - you are correct, dbSeeChanges is required on any updateable recordset to a SQL Server database.

harfang - I'm going to try ADO, just to get more familiar with it in any event. I can always go back to kelvinsparks suggestion and just use a stored procedure....

Thanks Team! I wanted to check with you guys just to make sure I wasn't doing anything really dumb...(been known to happen).
bcote
0
 
harfangCommented:
Thanks for the info on dbSeeChanges.
Does this mean you made it work?
In any case, thanks for points and grade, and good luck with your project!
(°v°)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.