Solved

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

Posted on 2006-06-19
4
417 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:blcote
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
harfang earned 100 total points
ID: 16939038
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
 
LVL 22

Assisted Solution

by:Kelvin Sparks
Kelvin Sparks earned 150 total points
ID: 16942001
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
 

Author Comment

by:blcote
ID: 16942414
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
 
LVL 58

Expert Comment

by:harfang
ID: 16943503
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now