Loading ...
Sorry, an error occurred while loading the content.

XML Type in Management Studio

Expand Messages
  • Andy Mills
    Hello All: I am having an issue. I am getting an error when trying to call a stored procedure from code. In order to debug the issue, I am trying to call the
    Message 1 of 2 , Apr 4, 2012
    • 0 Attachment
      Hello All:

      I am having an issue. I am getting an error when trying to call a stored procedure from code.

      In order to debug the issue, I am trying to call the stored procedure from inside SQL Server Management Studio, doing the following:

      EXEC dbo.Attachments_SaveFileXml()

      And then passing in some variable information, but I am getting the following error:
      XML parsing: line 1, character 39, unable to switch the encoding

      The code looks as follows:
      DECLARE @xmlDoc xml,
      @AttachedTable varchar(50),
      @AttachedTableKeyValue int,
      @DivisionId int,
      @ModuleId int,
      @UserName varchar(50)

      SET @xmlDoc = '<?xml version="1.0" encoding="utf-16"?><ArrayOfAttachmentFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><AttachmentFile FileId="-1" DivisionId="1" CategoryId="-1" FileTypeId="4" ResolutionId="-1" Title="Image" FileName="39thPAMonument-03.jpg" FolderPath="/Uploads/Images/True Temper/NewItems/" Size="147706" DisplaySequence="0" IsThumbnailImage="false" IsActive="true" ModifiedBy="rcarbo" ModifiedOn="2012-04-04T00:00:00-04:00" CurrentUser="rcarbo" HasChanged="true" IsDeleted="false" /></ArrayOfAttachmentFile>'
      SET @AttachedTable = 'NewItemRelatedImages'
      SET @AttachedTableKeyValue = 1
      SET @DivisionId = 1
      SET @ModuleId = 18
      SET @UserName = 'rcarbo'

      EXEC dbo.Attachments_SaveFileXml
      @xmlDoc,
      @AttachedTable,
      @AttachedTableKeyValue,
      @DivisionId,
      @ModuleId,
      @UserName

      The error is pointing to the definition of @xmlDoc. I tried to do a CAST( @xmlDoc AS XML) to another variable that is defined as XML, but get the same error on the CAST.

      How do I set this up so I can run the query to find out the issue?

      Thanks
      Andy











      [Non-text portions of this message have been removed]
    • Joe Fawcett
      Andy I d try removing the XML declaration during testing ( ). It maybe that SSMS doesn t use UTF-16 for its editor. It
      Message 2 of 2 , Apr 5, 2012
      • 0 Attachment
        Andy

        I'd try removing the XML declaration during testing (<?xml version="1.0"
        encoding="utf-16"?>).

        It maybe that SSMS doesn't use UTF-16 for its editor. It won't matter when
        you go live, as long as the actual file is UTF-16 then you can re-instate
        the declaration.

        Regards

        Joe
        http://joe.fawcett.name/


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.