Solved

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

Posted on 2006-06-19
4
428 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access to SQL Conversion - Bit and Yes/No Datatypes 12 46
DSum for Access 6 44
DBF to ... Converter 5 40
Set focus on next field when character count = 5 9 12
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

910 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

20 Experts available now in Live!

Get 1:1 Help Now