>>>>>>Hi there,
>>>>>>
>>>>>>We are in the process of upgrading our databases from Sql Server 2005 to Sql Server 2012. All ports have been successful except one database that I designed 9 years ago.
>>>>>>
>>>>>>Every table has a primary index and most have foreign keys. Trying to update any record in any table with at least a foreign key generates an error "Syntaxe incorrecte vers '@error_number' " that translates into something like "'ncorrect syntax to '@errornumber' "
>>>>>>
>>>>>>There are no special user rights involved.
>>>>>>
>>>>>>The port has been done (1) with detach / attach and (2) from a backup and I observe the same behavior, which is somewhat reassunring :)
>>>>>>
>>>>>>The database is not set as readonly.
>>>>>>
>>>>>>I have compared the SQL 2005 and 2008 db instances and see no difference.
>>>>>>
>>>>>>So what?
>>>>>>
>>>>>>José
>>>>>
>>>>>Start SQL Profiler and see what is executed.
>>>>Thanks Borislav,
>>>>
>>>>I show you the result in the attached picture (I am using Toad for SWL Server 6.0).
>>>>
>>>>Also I have to rephrase my last sentence: >I have compared the SQL 2005 and 2012 db instances and see no difference.
>>>
>>>This is Execution plans, you need to run SQL Profiler (SSMS menu Tools->SQL Server Profiler)
>>
>>Hmm, sorry for using the wrong tool. The profiler has only two lines regarding this operation. Perhaps will you see something special.
>>
>>José
>
>That is what you need.
>Just copy and paste these line in New Query editor of SSMS and run it.
>Then you will see where the error occurs.
Ok, I hadn't notices the improvements in SSMS.
Running my very short code there raised an error that is easy to locate:
Msg 102, Niveau 15, État 1, Procédure T_U_Catalogue, Ligne 60
Syntaxe incorrecte vers '@error_number'.
So the trigger is the cause. Here is the code (generated by xCase):
USE [Softex];
GO
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE TRIGGER [dbo].[T_U_Catalogue] ON [dbo].[Catalogue] FOR UPDATE AS
BEGIN
DECLARE
@row_count INT,
@null_row_count INT,
@error_number INT,
@error_message VARCHAR(255)
SELECT @row_count = @@rowcount
IF @row_count = 0
RETURN
IF UPDATE([FK_iOldCodeId])
BEGIN
SELECT @null_row_count =
(
SELECT COUNT(*)
FROM inserted
WHERE [FK_iOldCodeId] is null
)
IF @null_row_count != @row_count
IF (
SELECT COUNT(*)
FROM [dbo].[cLookup] p, inserted i
WHERE p.[iID] = i.[FK_iOldCodeId]
)
!= @row_count - @null_row_count
BEGIN
SELECT @error_number=30002,
@error_message='Cannot update child in "[dbo].[Catalogue]".'
GOTO error
END
END
IF UPDATE([iID])
BEGIN
IF EXISTS (
SELECT 1
FROM [dbo].[Presentation] c, inserted i, deleted d
WHERE c.[FK_iCatalogueId] = d.[iID]
AND (i.[iID] != d.[iID])
)
BEGIN
SELECT @error_number=30004,
@error_message='Children exist in "[dbo].[Presentation]". Cannot modify Primary Key in "[dbo].[Catalogue]".'
GOTO error
END
END
RETURN
error:
RAISERROR @error_number @error_message
ROLLBACK TRANSACTION
END
GO
We are approaching.
José