SQL Function ERROR --> A transport-level error has occurred when receiving results from the server.

  • Hi!

    I created an sql function using C# and i deployed on sql server running on 64 bit os.

    Whenever I tried to call that sql function in select statement, It throw an error

    A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

    If I removed that sql function from the select statement , the statement's executed successfully.

    Can anybody help me with this error?

    Thanks

  • Please post the CLR code.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • This is the code that I used to create SQL Function

    using System;

    using System.Data;

    using System.Data.SqlClient;

    using System.Data.SqlTypes;

    using Microsoft.SqlServer.Server;

    using System.Text;

    using System.Runtime.InteropServices;

    namespace EncodingConversion

    {

    public partial class test

    {

    [Microsoft.SqlServer.Server.SqlFunction]

    public static SqlString ColumnEncodingToBig5( SqlString ColumnString)

    {

    if (ColumnString.IsNull == false &&

    !string.IsNullOrEmpty(ColumnString.Value))

    {

    System.Text.Encoding columnEncoding = System.Text.Encoding.GetEncoding(1252);

    System.Text.Encoding encBig5 = System.Text.Encoding.GetEncoding((int)950);

    System.Text.Encoding encUTF16 = System.Text.Encoding.Unicode;

    byte[] arrByte_ColEnc = columnEncoding.GetBytes(ColumnString.Value);

    byte[] arrByte_UTF16 = System.Text.Encoding.Convert(encBig5, encUTF16, arrByte_ColEnc);

    string result = encUTF16.GetString(arrByte_UTF16);

    if (!string.IsNullOrEmpty(result))

    {

    return new SqlString(result);

    }

    }

    return SqlString.Null;

    }

    }

    }

  • I notice that you do not have any exception handling. However, BOL has this to say about the GetEncoding method which you are using:

    Note

    Some unsupported code pages cause ArgumentException, while others cause NotSupportedException. Therefore, you must catch all exceptions indicated in the Exceptions section.

    So I would recommend adding some exception handling.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

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

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