Error message when you use the correct syntax of the CREATE TYPE statement in SQL Server 2005: "Incorrect syntax near 'ObjectName'"

Symptoms

Consider the following scenario. In Microsoft SQL Server 2005, you use the correct syntax of the CREATE TYPE statement to create a common language runtime (CLR) user-defined type in a database. The compatibility level of the database is set to 80. In this scenario, you receive the following error message:
Server: Msg 102, Level 15, State 1, Line 2

Incorrect syntax near 'ObjectName'.
However, you receive the expected error message if you do the following:
  • You use the CREATE PROCEDURE statement or the CREATE FUNCTION statement.
  • You create a CLR stored procedure or a CLR function.
The error message contains the following text:
Server: Msg 325, Level 15, State 1, Procedure ObjectName, Line 4 Incorrect syntax near 'external'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the stored procedure sp_dbcmptlevel.

Resolution

To resolve this problem, you must set the compatibility level of the database to 90 when you try to create CLR objects on the database. To do this, run the following statement for the database:
exec sp_dbcmptlevel 'DatabaseName', 90
Note If you migrate a database from Microsoft SQL Server 2000 to SQL Server 2005, you must make sure that you set the compatibility level to 90 before you create a CLR object in the database.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Propriedades

ID do Artigo: 918039 - Última Revisão: 12 de jun de 2008 - Revisão: 1

Comentários