I'm adding onto this thread to help out others. I can't count the
number of times I'm searching for a solution and people don't follow
up with the answers.
Here is a great SQL script that will do a Find / Replace for the ntext
datatype used in column AllXml. I used the script to replace the
invalid XML. BTW, I'm choose a valid value from thin air.
Here is the URL I found this gem:
http://sqlserver2000.databases.aspfaq.com/how-do-i-handle-replace-within-an-ntext-column-in-sql-server.html
DECLARE
@TextPointer BINARY(16),
@TextIndex INT,
@oldString NVARCHAR(32), -- change to VARCHAR
@newString NVARCHAR(32), -- change to VARCHAR
@lenOldString INT,
@currentDataID uniqueidentifier
SET @oldString = N'�'; -- remove N
SET @newString = N'
'; -- remove N
IF CHARINDEX(@oldString, @newString) > 0
BEGIN
PRINT 'Quitting to avoid infinite loop.';
END
ELSE
BEGIN
SET @lenOldString = DATALENGTH(@oldString)/2; -- remove /2
DECLARE irows CURSOR
LOCAL FORWARD_ONLY STATIC READ_ONLY FOR
SELECT
ErrorId
FROM
dbo.ut_ELMAH_Error
WHERE
PATINDEX('%'+@oldString+'%', allxml) > 0;
OPEN irows;
FETCH NEXT FROM irows INTO @currentDataID;
WHILE (@@FETCH_STATUS = 0)
BEGIN
SELECT
@TextPointer = TEXTPTR(allxml),
@TextIndex = PATINDEX('%'+@oldString+'%', allxml)
FROM
dbo.ut_ELMAH_Error
WHERE
ErrorId = @currentDataID;
WHILE
(
SELECT
PATINDEX('%'+@oldString+'%', allxml)
FROM
dbo.ut_ELMAH_Error
WHERE
ErrorId = @currentDataID
) > 0
BEGIN
SELECT
@TextIndex = PATINDEX('%'+@oldString+'%', allxml)-1
FROM
dbo.ut_ELMAH_Error
WHERE
ErrorId = @currentDataID;
UPDATETEXT dbo.ut_ELMAH_Error.allxml @TextPointer
@TextIndex @lenOldString @newString;
END
FETCH NEXT FROM irows INTO @currentDataID;
END
CLOSE irows;
DEALLOCATE irows;
END
On Aug 28, 12:33Â pm, Atif Aziz <
Atif.A...@skybow.com> wrote:
> > Visual Studio tells me � is illegal.
>
> That is indeed an invalid character as per XML spec. The valid ranges defined are:
>
> Char ::= #x9 | #xA | #xD
> Â Â Â Â Â | [#x20-#xD7FF]
> Â Â Â Â Â | [#xE000-#xFFFD]
> Â Â Â Â Â | [#x10000-#x10FFFF]
>
> Seehttp://
www.w3.org/TR/REC-xml#charsetsfor more.