Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Development
Developer's Guide
 XML Serialization from CLR Database...
Community Content
In this section
Statistics Annotations (1)
Collapse All/Expand All Collapse All
Other versions are also available for the following:
SQL Server 2008 Books Online (October 2009)
XML Serialization from CLR Database Objects

XML serialization is required for two scenarios:

  • Invoking Web Services from common language runtime (CLR) objects.
  • Converting a user-defined type (UDT) to XML.

Performing XML serialization by invoking the XmlSerializer class normally generates an additional serialization assembly that is overloaded into the project with the source assembly. However, for security purposes, this overload is disabled in the CLR. Therefore, to call a web service or perform conversion from UDT to XML inside SQL Server, the assembly must be created manually using a tool called Sgen.exe provided with the .NET Framework that generates the necessary serialization assemblies. When invoking XmlSerializer, the serialization assembly must be created manually by following these steps:

  1. Run the Sgen.exe tool that is provided with the .NET Framework SDK to create the assembly containing the XML serializers for the source assembly.
  2. Register the generated assembly in SQL Server using the CREATE ASSEMBLY statement.

For information about errors that you may receive when performing XML serialization, see the following Microsoft Support article: "Cannot load dynamically generated serialization assembly".

For information on data types that are not supported by XMLSerializer, see XML Schema Binding Support in the .NET Framework in the .NET Framework documentation.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Using VS2008 some details.      Tom Groszko   |   Edit   |   Show History

Add the following including the double "s to the project properties Build Events Post-build event command line dialog
The path is the path to sgen.exe, I could not find one in VS2008 so I used the one in VS2005

"C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /force "$(TargetPath)

This will create an additional .DLL in your output directory
ProjectName.XmlSerializers.dll

Define this assembly to SQL Server
CREATE ASSEMBLY SomeAssemblyName FROM 'The path to your project \bin\Release\ProjectName.XmlSerializers.dll'
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker