Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-06-19
4
Medium Priority
?
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
harfang earned 400 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 600 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

722 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