We have been using a Delete command on Access 2003 with xp machine from past few years and it was working good until we upgraded our systems to Access 2010 and Windows 7.
Please see the error below. No sure what i was missing. I tried creating a new link oracle table, but it didn't work.
I just ran into the same lock error when trying to update a linked SQL Server table via MS Access 2010.
This may no longer be a problem for you since the thread is so old, but hopefully it makes it easier on someone else in the future.
I was able to fix it by changing the ID field in SQL Server from a bigint to an int.
You may also want to make sure that "Default record locking" is set to "No locks" in Access Options --> Client Settings --> Advanced
DefaultRecordLocking http://www.tmetrics.net/support/patrick/stackoverflow/defaultrecordlocking.jpg
I had this error with a linked table that had a primary key and a unique key. When linking the table, Access assumed the unique key was the primary key.
By temporarily disabling or deleting the unique key and refreshing the ling using Linked Table Manager" the problem was resolved.
It appears that the 332 records it can't delete are locked, perhaps by some other process? Is there a stagnant process running somewhere that is holding a lock on those records?
I had a similar problem... Could delete records manually, but through query was getting that message.
Even though I was deleting records in the "many" table in a one-to-many relationship, a "key violation" message kept appearing.
I edited the relationship to ADD Cascade Update and Cascade Delete, and the problem went away.
I am having this problem. I have an Access front-end to an Oracle database. I am trying to delete records from a linked table. I have not found a solution anywhere on the internet. Here is my "solution".
I converted from DoCmd.RunSQL to DBS.Execute to run my Delete query. That got rid of the error message. But not all records were being deleted still. So now I execute the delete query in a loop.
recCount = DLookup("count(*)", "my_table")
Do While recCount > 0
DBS.Execute "DELETE * FROM my_table", dbSeeChanges
recCount = DLookup("count(*)", "prod_nmpsia_premiums")
Loop
Sometimes it only takes one pass. Other times it takes a few.
I know it's a kludge. But it works.
I was running into this same issue using Access 2016 and an Oracle database. I could append to the Oracle tables just fine, but when I ran the delete query to remove those same records, it would delete some records and say others were locked. If I looped the query enough times it would eventually erase all the records.
The solution I found was in the Access delete query, I set the 'Use Transactions' property to 'No' and it started working fine without any record locks. I don't know if this is a perfect solution, but it is working in my case.
--Update--
The above solution worked for some of my queries but then I still ran into the issue on other queries. So it helped in some cases but didn't work completely.
What does seem to be working now is that I stored a Procedure in Oracle that would delete the data I needed to delete and I am calling that procedure from Access.
Related
I have in Microsoft Access a linked table to an ASE Server.
On the server side, the table has no primary key or identity columns.
And has a trigger on insert that validates new entries, so that when the entry is not validated it deletes the entry from the table and writes to "table"_ERR to let the users know what error was produced.
When linking it to Access a composite key is created using 10 columns.
I have this same setup in 10 different tables (all with triggers all linked to Access)
In this particular table when trying to insert/append records to the table through Access i always get the error message:
Single-row update/delete affected more than one row of a linked table. Unique index contains duplicate values.
This error occurs when both table and table_ERR are empty and i'm only trying to insert 1 record.
If I disable the trigger i have no problem inserting records through Access
I have similar triggers in other tables that are working correctly.
What can be causing this issue and does anyone know how to solve this?
I have read that MS Access can mess up the ##identity, even so none of the solutions presented online seem to work.
links : https://groups.google.com/forum/#!msg/microsoft.public.sqlserver.programming/McHdRpPKMhs/SlyObU8w7JMJ
Stop Access from using wrong identity when appending to linked table on SQL server
Thanks in advance.
EDIT: if i try to insert the records directly from a management software (like Aqua Data Studio) there are no erros
Without knowing more specifics about your data itself, it is difficult to say why this might be happening.
However, it sounds like in this specific instance for this specific linked table, your 10 columns are not unique enough to prevent non-distinct rows from being selected.
Suggested fixes:
Add a primary key. Honestly, probably the best and easiest choice.
If for some reason you cannot add a new column to (or alter) your table; you may be able to re-link your table, and re-choose your 10 columns so that they are more unique.
Beyond that, I think we would need more information.
Just out of curiousity, what is the reason for having no key?
I am running a simple update statement:
UPDATE sometab
SET `somefield1` = '19',
`somefield2` = '3734941'
WHERE somefield3 = '1234';
and I am getting the error:
ERROR 1146 (42S02): Table 'prod._sometab_new' doesn't exist
I can successfully select from the table where somefield3 is 1234.
Why am I getting a table doesn't exist error for a table that exists? And why does the error message refer to a different table? I don't see any triggers associated with the table.
Additional information: A colleague just noticed that it is referring to a prod scheme, but the statement is running in a dev schema built from prod. The update statement works in DBs that were built a few days ago using the same method, but all of the DBs built after some, as of yet, unknown time exhibit the error.
The current theory is that a conversion script to move us to UTF-8 is currently running and creating tables like _ORIG_new as part of its conversion. We are going to wait for the conversion script to finish and then rebuild the dev databases and see if the error still persists.
Does this happen if you also try Insert into or Delete statements ?
Insert INTO sometab(somefield1, somefield2) VALUES (a, b).
If that works you should not have problems probably, otherwise you have problems accessing your database.
Second, are you sure you are using the correct database file and that are you connected to it properly. If you are using it in external application (c#), check your connection strings.
Also check how are you executing the query. I cant think of other more specific solution to your problem
I have an Access database front-end and I'm trying to put a button on a form to delete the current record. I used the following VBA code to delete the record:
If Me.NewRecord Then
Me.Undo
Exit Sub
End If
DoCmd.RunCommand acCmdDeleteRecord
Me.Requery
Me.Refresh
When I run this on records that I inserted into the database with the form, It returns Run-time error '2501' on the DoCmd. However, if I run it on a record that had already existed in the database then the code completes as intended.
Additionally, no one else is accessing this database table yet and I only had the one form open.
When I went to delete them from the linked table manually in access I got the same error but I was able to delete them from the database using SQL Server Management Studio.
What would cause this to happen?
EDIT
I did some more investigating and found that I am unable to edit the new records in in the base table using access either. I get an error about the records being changed by another user.
Other than the recommendation to have a timestamp field in the table (SSMA assistant adds this to all tables when you use it to upsize from Access, and it's definitely something I'd recommend), I have some criticism of your code. I'd write it this way:
If Me.NewRecord Then
Me.Undo
Else
DoCmd.RunCommand acCmdDeleteRecord
Me.Requery
End If
The refresh is redundant after a requery, as you already have the most recent data.
Using Exit Sub is helpful for guard clauses on things that aren't mutually exclusive, but in this case you have an either/or -- either your going to delete an existing record or undo a new record. That can be handled within a single If/Then/Else block and then you have a single exit point for your subroutine, which is very helpful in case the code grows more complex in the future.
This is not the answer to your specific problem, but regarding the question title of getting Error 2501 while trying to delete a record, another situation where that happens is this:
You try to delete a row in one table that would orphan rows in another
table (because the two tables are linked via a foreign key). SQL
Server rejects the deletion and Access returns that vague 2501 error
code.
In my case, I solved the issue by dropping and recreating each foreign key with ON DELETE CASCADE so that when a row in the "main" table is deleted via Access, SQL Server automatically deletes the corresponding rows in the each "detail" table.
See these questions for more detail on cascade delete:
Good explanation of cascade (ON DELETE/UPDATE) behavior
How do I use cascade delete with SQL Server?
I am fairly new to using mysql. I have an application that performs some basic querying. I am also trying to run a simple delete statement -
delete from mydb.mytable
This table is a simple 2 column table with not keys or triggers or anything defined. For some reason, the delete is not being performed. If I run the statement from MySql Workbench in the query window, it works fine. From the code, it does nothing. I am not seeing any error messages. I created a user with select, insert, update and delete rights to the schema. I am able to do the insert fine, but the delete does not seem to be working.
Is there a setting for mysql that I am missing that will not allow me to perform the delete?
Thanks for any thoughts.
Fist of all, check if
you are connected to the right database ;
you are using transaction and forgetting 'commit' ;
the user you use have enough permissions to delete from the table .
As a side notice, if you want to delete all records, you should use truncate instead of delete
Are you using transactions? My first guess is that your code might be issuing a BEGIN TRANSACTION without a COMMIT.
We would have to see some of your code to answer the question.
My guess is that you are not calling commit from your code. You can configure MySQL to auto-commit your queries, but this is usually not what you want.
Ok. Quick background:
MS Access 2003 with 2003/2003 format MDB file upgraded from Access 97.
For the purposes of this example, there are two tables.
Table 1
Asset
ID - (text 20)
ParentID - (text 20)
Other fields
AssetRels
ID - (text 20)
When a record is added to Asset, the ID is added to AssetRels.
From Asset.ID to AssetRels.ID there is a relationship that exists that enforces referential integrity with cascade update and cascade delete.
From AssetRels.ID to Asset.ParentID there is a relationship that enforces referential integrity with cascade update only.
I have 2 records in Asset
VACU0703200, NULL
VACU0703250, VACU0703200
In the data DB, I can go into the table and change VACU0703200 to VACU0704500 and the changes propogate as expected.
If I open the front end DB that links to the data DB, and try the same change (in the table directly) I get "Could not update; currently locked" (no, nothing about 'another session', that's the whole error message)
Both databases are set to "no lock" for the "default record locking"
Obviously, there is some difference in row/page/table level locks that is preventing the cascade update from working.
Does anyone know of some property settings that I can use somewhere to stop this error?
I would prefer not to have to remove the relationship, but otherwise I might have to, and handle it in code.
Edit: Cause is that the table contains a Memo field. Apparently via the linked table, having the Memo field overflow the 4K row size escalates to a table lock. which in turn triggers the problem.
Solution (hackish) is to prevent edits to the ID field on the form, and add a new form to rename. Save changes before opening the new form, and performing the update via an update query works.
I don't see why moving to the front end and editing this from a linked table should make any difference. I would however delete the table links, and then RE link. Often sometimes some properties are set up and read a time of linking, if you go to the back end database and change some of the table properties, often it's a very good idea to RE link the tables.
As a general rule, you more often have to do the above when you add new columns with linked tables to SQL server. However, I would suggest you delete your linked tables in the front end, and try RE linking, this should fix this problem.
Solution (hackish) is to prevent edits to the ID field on the form, and add a new form to rename. Save changes before opening the new form, and performing the update via an update query works.
The cause is a table lock escalation that occurs when the text overflows the 4K table row limit.