WebService Return bing cut off at 40 chars asp.net VB

I am trying to return an encriptyed id from a table that is about 60 chars. But every time I run the web service it limits the return to 40 chars.

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Data

<WebService(Namespace:="http://blah.com/")> Public Class LeasorVerify

    Inherits System.Web.Services.WebService
    <WebMethod()> _
       Public Function LeasorVerify(ByVal UserName As String, ByVal Password As String) As System.Data.DataSet
        Dim conn As New System.Data.SqlClient.SqlConnection("Database=DB;Server=Server;uid=username;passwordPassword")
        Dim ds As New System.Data.DataSet()
        Dim adapter As New System.Data.SqlClient.SqlDataAdapter()
        adapter.SelectCommand = New System.Data.SqlClient.SqlCommand("EXEC      [dbo].[sp_Verify]  @UserName = " & UserName & ",@Password=" & Password, conn)
        adapter.Fill(ds, "Info")
        Return ds
    End Function

End Class

This returns the name of the customer and a encrypeted id. The encrypted id that is returned is 40 chars everytime.
Who is Participating?
aha! varbinary(max) is the problem!

maybe try to convert the data into a hex string first check this article out about how best to deal with this: http://sqlblog.com/blogs/peter_larsson/archive/2010/01/27/convert-binary-value-to-string-value.aspx

anyway.. the issue is that in order to read the actaul data in a varbinary column, you have to stream the data from teh dataset.
Tom BeckCommented:
You should be able to specify the length of each parameter like this:

        adapter.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.VarChar, 50, "UserName"))
        adapter.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Password", System.Data.SqlDbType.VarChar, 100, "Password"))
From what I see in your code, it does not sound like a problem with your input parameters. I suggest you investigate the [sp_Verify] stored procedure. Check that the encrypted string is not being restricted... there might be a SELECT CAST(fieldInQuestion as varchar(40)) or something that is affecting you there.

Also check if executing that stored procedure directly from SQL Server Management Studio returns the correct data...
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

soccerman767Author Commented:
Yes it does return the correct data from the SP
you need quotes in this line:

adapter.SelectCommand = New System.Data.SqlClient.SqlCommand("EXEC      [dbo].[sp_Verify]  @UserName = " & UserName & ",@Password=" & Password, conn)

Open in new window

like so:

adapter.SelectCommand = New System.Data.SqlClient.SqlCommand("EXEC      [dbo].[sp_Verify]  @UserName = '" & UserName & "',@Password='" & Password & "'", conn)

Open in new window

as to the truncation... I'm afraid I cannot see where that could be coming from since the stored procedure returns the correct data. what datatypes are the columns in the return data? is there some form of conversion being done by .NET?
soccerman767Author Commented:
The field in the table is varbinary(max). I am not declaring a return variable. The SP is just returing the results of an query.    

I am new to web services so I am assuming it is like you say      a .net limit on the return string.
if you have sql server 2005, try to view the varbinary column. you will see that it does not really show the data... well.. it's something along those lines. am not too sure how best to return a varbinary column from a web service.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.