Hello everybody, I've encountered the following problem which I can't explain to myself.My setup is: SQL 2014 + Linked server (name it 'EXTSYS') to a MySQL DB (v.5.1.73) through ODBC ConnectorEXTSYS has two tables, EntityMaster and EntityDetail, linked by a foreign key from Detail to MasterSQL 2014 has a stored procedure to write in EXTSYS new Entities, writing first on EntityMaster and then on EntityDetail.My INSERT syntax is something like [code="sql"]INSERT INTO OPENQUERY(EXTSYS, 'SELECT id, createdtime, modifiedtime FROM EntityMaster') (id, createdtime, modifiedtime)VALUES (131177, getdate(), getdate())INSERT INTO OPENQUERY(EXTSYS, 'SELECT id, name, surname, company FROM EntityDetail') (id, name, surname, company)VALUES (131177, 'TestName', 'TestSurname', 'TestCompany')[/code]Result is the following:- First INSERT goes ok, in MySQL I find the new inserted record- Second INSERT fails with the following message "Cannot add or update a child row: a foreign key constraint fails (`MySQLschemaname`.`EntityDetail`, CONSTRAINT `fk_1_EntityDetail` FOREIGN KEY (`id`) REFERENCES `EntityMaster` (`id`) ON DELETE CASCADE)"BUT....if I change my INSERT syntax like this[code="sql"]EXECUTE ('INSERT INTO EntityMaster (id, createdtime, modifiedtime) VALUES (131177, NOW(), NOW())') AT EXTSYSEXECUTE ('INSERT INTO EntityDetail (id, name, surname, company) VALUES (131177, ''TestName'', ''TestSurname'', ''TestCompany'')') AT EXTSYS[/code]everything goes ok.It seems some sort of COMMIT problems with OPENQUERY or caching (?) with OPENQUERY that EXECUTE bypasses.EXECUTE is not a valid option because I would like to use OPENQUERY to prevent Injection and/or value cleaning. Can anyone explain me if it's possible to correct my OPENQUERY syntax to avoid the "foreign key" error?Thanks a lot!
↧