I need help in writing queries which will update MySql tables from SQL server.
I have created linked server and select queries work fine but I'm getting errors while doing update. I'm really new to writing such type of queries so please help me understanding error message and what it means.
My update query:
UPDATE openquery(stagedb_za, 'Select acm_flag FROM aol_center WHERE nid = 6439')
Set acm_flag = 'P'
Error:
OLE DB provider "MSDASQL" for linked server "stagedb_za" returned message "Row cannot be located for updating. Some values may have been changed since it was last read.".
Msg 7343, Level 16, State 4, Line 1
The OLE DB provider "MSDASQL" for linked server could not UPDATE table "[MSDASQL]". The rowset was using optimistic concurrency and the value of a column has been changed after the containing row was last fetched or resynchronized.
This whole issue goes away with a setting on the MySQL ODBC connector.
On the SQL Server that is linking to MySQL, go into the configure screen on the MySQL ODBC connection that is used by the linked server. Open "Details". On the "cursor/results" tab. Place a check in the "Return matched rows instead of affected rows".
Upon making that configuration change, updates that set a MySQL field value to the value it already has will not return an error.
Before I discovered this on another forum, I had put a LOT of code in to filter out the offending values on a field by field basis. This is easy.
Ok, I got the answer.
It seems like when your are updating column value and if new value is same as existing one then it is treated as there is no change so no updation will happen.
In my case I was updating acm_flag to 'P' but it's value was already 'P' so no updation happened. When I tried to update it to different value it worked just fine.
Related
I have a problem using an Access Application connected to a MySql Database.
I test UPDATE on one small table with a VBA procedure, using DAO
UPDATE tblFormateur
SET Prenom = 'Werner'
WHERE Nom='HEISENBERG' "
The first time I run the query, it's ok.
But if I run the same query, without changing the value,(keeping Prenom = 'Werner')
I get an error message saying that the query has not been executed,
due to a lock violation.
If I run the query again, but with a different value, e.g Prenom = 'Peter',
the query is executed without error.
On the other hand, If I do the same experiment with ADODB,
I do not get any error.
One can say: let's go with ADODB!
The problem is that the Access application Forms use DAO, not ADODB!
So all the forms won't be able to either add new records or update records.
Did you experienced the same issue?
Are there some parameters of the ODBC driver that needs to be set?
Thank's advance for any help.
Windows 11
Access Office 365
ODBC connector 8.0 CE
If you have a linked table as form RecordSource and you run an update query, it always give you this error.
The error appears because Access do not detect any changes. If you have a field with value 'Test' and than you delete this value, rewrite 'Test', Access doesn't detect any changes because the value is the same.
To bypass this error you can make a random field that add n + 1 before running your query. When you open the form, field is set to 0, before you run the query is 1, next time is 2 and so on.
Access will detect changes to the form and won't give you this error.
I have a problem with my current data flow, where I try to delete entries, that already exist in my SQL DB. Based on the following thread, I am using a full outer join and an Alter Row step to get rid of duplicate entries: ADF copy data activity - check for duplicate records before inserting into SQL db
The only difference is, that the attribute _id is of the data type varchar.
I followed all the necessary steps:
And that is the preference of my AlterRow step:
Moreover, I am facing a strange problem, that I regularly have to set up the mapping of FixNames#{_id} as Azure detects it as an error. Setting it up again in the mapping part, the error is gone.
An altenative could be a stored procedure, but I don't understand, why the duplicates with my current version are still inserted.
Insert one row successfully, but with a ODBC call failed error. Then it keeps on failing with
failed to insert new row in the recordset due to system error
for row 2 ... to n. But can write many rows to a local Access table successfully. Write to SQL , 1 row only.
After recreating a table on SQL with schema as close to Access' as possible, this problem has been resolved. Not exactly sure what made the differences, but issue resolved.
When I try to update my customer table that is on linked server, from my procedure on mssql server, I get this error:
OLE DB provider "MSDASQL" for linked server "PRESTA" returned message "Row cannot be located for updating. Some values may have been changed since it was last read.".
Msg 7343, Level 16, State 4, Line 1
The OLE DB provider "MSDASQL" for linked server "PRESTA" could not UPDATE table "[PRESTA].. [prs_customer]". The rowset was using optimistic concurrency and the value of a column has been changed after the containing row was last fetched or resynchronized.
I am 100% sure that the value I am trying to put in the birthday column of my Customer table is not the same as the value that is already in it:
UPDATE PRESTA...prs_customer
SET birthday = #birthday
WHERE id_customer = #id_customer
This error is showing only because the value already in birthday column is: "0000-00-00", and not null. When I change directly in database to real NULL, my procedure works, and it doesn't give any errors.
Also, both values are of type DATE, have the same format, so that is not a problem.
I am baffled by this, so if anyone please elaborate?
Just read the error message. The link server is using optimistic concurrency. Thus, a record is read via a cursor in the OLE DB layer. When you try to perform the update, the data has changed. Optimistic means use locking just before you do an update.
Are you sure this is the exact SQL statement?
Are there any other processes that might change the id during your update?
Check out the ADO book from MS Press.
http://web.archive.org/web/20021222065228/http://www.microsoft.com/mspress/books/sampchap/3445.asp
It shows the same error you are experiencing.
Unless it is a bug in the OLE DB provider or MySQL, it looks to me as a locking issue.
Can you increase the locking level to pessimistic? If you do, you will have to handle blocking in your code.
I would also run a trace in MySQL to see what statements are hitting the DB Engine.
Sincerely
John
I am trying to set up a third party MySQL as a Linked Server on SQL Server 2008.
When I try to access the data via a simple OpenQuery below I get an error.
SELECT * FROM OpenQuery(SERVERNAME, 'SELECT * FROM table')
The error message:
OLE DB provider 'MSDASQL' for linked server 'SERVERNAME' returned data that does not match expected data length for column '[MSDASQL].tablename'. The (maximum) expected data length is X, while the returned data length is Y.
NOTE:(where X > Y)
I've tried with another MySQL table that I built myself and it works fine. Therefore I assume the problem might be with the MySQL source.
EDIT: After digging a little deeper into the MySQL data I found several "invalid" dates such as zero dates. These could be a reason, however I have no way to change the data source so I must find a way to convince SQL to ignore it.
I recall something form previous versions of SQL where you could switch to "Lazy Schema Validation" to force SQL not to check this. However this option appears to be gone in 2008.
Any ideas how I could make this work?