How to upgrade or downgrade an assemblyIn SQL Server 2005, you can use the ALTER ASSEMBLY statement to upgrade or downgrade a stand-alone assembly that was not created with a strong name. For a strong-named assembly, you can upgrade but cannot downgrade the assembly by using the ALTER ASSEMBLY statement.
You cannot upgrade or downgrade an assembly in the following scenario:
- Assembly A is created for a CLR object in an instance. Assembly A has a referenced assembly. The referenced assembly is assembly B.
- Assembly B has no referenced assembly.
- You recompile assembly A to reference a different version of assembly B.
This behavior occurs because SQL Server creates a CLR fusion policy when you create assembly A. This CLR fusion policy automatically maps the version of assembly B in the metadata of assembly A to the actual version of assembly B. SQL Server loads the new version of assembly B at run time when you upgrade or downgrade assembly B to some other version. This behavior occurs even though assembly A refers to the original version of assembly B. However, when you try to upgrade or downgrade assembly A when assembly A contains a new version of assembly B in the metadata, the ALTER ASSEMBLY statement will fail, and you receive error messages that resemble the following:
ALTER ASSEMBLY failed because the identity of referenced assembly 'RefAsm' has changed. Make sure the version, name, and public key have not changed.
ALTER ASSEMBLY failed because the referenced assemblies would change. The referenced assembly list must remain the same.
Upgrade or downgrade the assemblyNotes
- These steps upgrade or downgrade assembly A in the scenario that was described in the "How to upgrade or downgrade an assembly" section.
- This example assumes that the versions of the two assemblies are both 22.214.171.124 and the assemblies are both written in C#. When you follow these steps, you try to upgrade assembly A and assembly B to version 126.96.36.199.
- Back up version 188.8.131.52 of assembly B to a folder.
- Modify and then recompile assembly B to version 184.108.40.206.
- Use the ALTER ASSEMBLY statement to upgrade assembly B in SQL Server 2005.
- Modify and then recompile assembly A to version 220.127.116.11. When you do this, reference version 18.104.22.168 of assembly B from the backup that you made in step 1. To do this, use the Csc.exe compiler tool together with the /reference switch. For example, use the following command:csc /target:library /out:AssemblyA.dll AssemblyA.cs AssemblyInfo.cs /reference:"BackupFolder\AssemblyB.dll"Note To verify the version of assembly B in the metadata of assembly A, open assembly A by using the Ildasm.exe utility. Then, verify the metadata information for the referenced assembly under the MANIFEST section.
- Use the ALTER ASSEMBLY statement to upgrade assembly A in SQL Server 2005.
How to downgrade a strong-named assemblyIf you use a strong-named assembly for a CLR object, SQL Server 2005 does not support using the ALTER ASSEMBLY statement to downgrade assemblies. If you try to downgrade the version of an assembly by using the ALTER ASSEMBLY statement, you receive an error message that resembles the following:
Alter assembly from 'Asm1, version=22.214.171.124, culture=neutral, publickeytoken=3a52b896cff0513d, processorarchitecture=msil' to 'Asm1, version=126.96.36.199, culture=neutral, publickeytoken=3a52b896cff0513d, processorarchitecture=msil' is not a compatible upgrade.
- Drop all objects that depend on the assembly.
- Drop the newer version of the assembly.
- Create the older version of the assembly.
- Create all required objects that depend on the assembly.
ID do Artigo: 917407 - Última Revisão: 13 de jun de 2008 - Revisão: 1