What's the biggest size of string I can use with SqlDbType?

Coreysan 1,816 Reputation points
2021-08-21T00:50:52.377+00:00

I'm using C# with ASP.NET, where the codebehind uses a string named wnotes with about 9500 bytes long. (string wnotes = "...")

When I call a stored proc, I pass the string this way:

        spCommand.Parameters.Add("@wnotes", SqlDbType.VarChar, -1).Value = wnotes; 

In the stored proc, it receives wnotes as:

       declare @wnotes varchar(max)

But after processing, I only see about 4000 get into the database.

Any thoughts?

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Bruce (SqlWork.com) 81,981 Reputation points Volunteer Moderator
    2021-08-21T15:22:56.8+00:00

    If the stored proc does any string manipulation of the variable @wnotes it may get truncated.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Ravi Kakarla 161 Reputation points
    2021-08-21T14:46:15.973+00:00

    If wnotes column data type is defined as either VARCHAR(MAX) or NVARCHAR(MAX), you should store more than 9500 bytes. Can you please share confirm wnotes column datatype?

    0 comments No comments

  2. Coreysan 1,816 Reputation points
    2021-08-22T03:30:08.863+00:00

    From what you both said, I'm going to assume it's something else I missed.
    You both sound confident that it's not this implementation, right?

    Codebehind:
    spCommand.Parameters.Add("@wnotes", SqlDbType.VarChar, -1).Value = wnotes;

    Stored Proc:
    declare @wnotes varchar(max);

    I'll look to see if I overlooked something!

    0 comments No comments

  3. Bruce Barker 801 Reputation points
    2021-08-22T15:19:04.483+00:00

    Another thought. How do you know it’s truncated? Maybe the tool is you use to view the data is truncating the data.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.