Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Incorrect syntax to '@errornumber' after upgrading to 20
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01577723
Message ID:
01577742
Vues:
71
This message has been marked as the solution to the initial question of the thread.
>>>>>>>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
>/*  Update Trigger '[dbo].[T_U_Catalogue]' for Table '[dbo].[Catalogue]'  */
>
>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
>
>/*  When updating a row in child '[dbo].[Catalogue]' ,the Foreign Key must be Null or exist in Parent '[dbo].[cLookup]'  */
>
>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
>
>/*  The Primary Key of '[dbo].[Catalogue]' cannot be modified if children exist in '[dbo].[Presentation]'  */
>
>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 Handling  */
>error:
>      RAISERROR @error_number @error_message
>      ROLLBACK TRANSACTION
>END
>
>GO
>
>We are approaching.
>
>José


From BOL:
RAISERROR (N'Error number %d message %s.', -- Message text.
           10, -- Severity,
           1, -- State,
           @error_number, -- First argument.
            @error_message); -- Second argument.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform