returning non-english data from sqlclr

  • Hi, I have a sqlclr procedure that takes a parameter and simply returns it back to the calling function. It works fine as long as the data is in english, but as I pass other language characters, I get back ???.

    The function is

    Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true, IsPrecise = true, DataAccess = DataAccessKind.Read)] public static string InvokeTestService(SqlString strTestData)

    {

    return strTestData.toString();

    }

    I call it from sql server as:

    declare @testData nvarchar(100)

    set @testData = N'新着情報'

    declare @ReturnedXML nvarchar(1000)

    Select @ReturnedXML = dbo.InvokeTestService(@testData)

    print @ReturnedXML

    The result coming back is ????. Would really appreciate help on this one.

    Thanks!

  • Set your output to be SqlString:

    [Microsoft.SqlServer.Server.SqlFunction]

    public static SqlString InvokeTestService(SqlString strTestData)

    {

    return strTestData;

    }

    It will return the correct value, but I am sure that you are masking another problem with this simple example, so can you explain what the real issue is if the above doesn't solve your problem?

    EDIT:

    Even if you need to deal with the input string as a native CLR String, you can still get the correct output from your function:

    [Microsoft.SqlServer.Server.SqlFunction]

    public static SqlString InvokeTestService(SqlString strTestData)

    {

    string testdata = strTestData.Value;

    return new SqlString(testdata);

    }

    If this doesn't answer your post, please explain what the issue is in detail, and maybe we can offer some better advice.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • Hi could any other language data be fed through sql server?? for example french text?? will the data be stored in french??

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply