string limit

T

tshad

Is there a string limit is C#?

I have a Textbox that I am allowing users to paste into (can be a word
document). But I am finding that I am losing data when I write large files
to my Sql Server database.

The fields is set to text. The data is kept in an object in a "string"
variable when I am moving from asp.net page to page.

One example had the data at 23k, but when I got the data back, it only have
7k in it.

What happened to the rest?

Thanks,

Tom
 
N

Nicholas Paldino [.NET/C# MVP]

Tom,

What is the definition of the field? If it is a varchar, then I think
the maximum that it can hold is 8000 characters (approximately).

You would be better off using text or varchar(max) (in the case of SQL
Server 2005) to store your field.

Hope this helps.
 
T

tshad

Nicholas Paldino said:
Tom,

What is the definition of the field? If it is a varchar, then I think
the maximum that it can hold is 8000 characters (approximately).

Turns out that was the the problem. I did have it defined as a text field,
but in one of my Stored Procedures, I had it set to varChar(8000). That was
what it originally was, but when I changed it, I missed that SP.

BTW, is there a limit on "string"?

Thanks,

Tom
You would be better off using text or varchar(max) (in the case of SQL
Server 2005) to store your field.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tshad said:
Is there a string limit is C#?

I have a Textbox that I am allowing users to paste into (can be a word
document). But I am finding that I am losing data when I write large
files to my Sql Server database.

The fields is set to text. The data is kept in an object in a "string"
variable when I am moving from asp.net page to page.

One example had the data at 23k, but when I got the data back, it only
have 7k in it.

What happened to the rest?

Thanks,

Tom
 
M

Mythran

BTW, is there a limit on "string"?

AFAIK, yes. The limit is the amount of free and availabe RAM plus the
available allowed size of the swap file on disk minus the size of the used
portion of the swap file...give or a take...

:p

Mythran
 
T

tshad

Thanks,

Tom

Mythran said:
AFAIK, yes. The limit is the amount of free and availabe RAM plus the
available allowed size of the swap file on disk minus the size of the used
portion of the swap file...give or a take...

:p

Mythran
 
G

Greg Young

This is wrong.

..NET strings are like ole bstrs, they contain an integer specifying their
length ... maximum size is uint.max - some bits (I forget how many which are
used for various flags by the framework itself)

Cheers,

Greg
 
G

Greg Young

also there would be a hard 2gb limit unless you hack up your version of
windows with /3gb in which case it would be 3 :)

Cheers,

Greg
 
J

Jon Skeet [C# MVP]

Greg said:
also there would be a hard 2gb limit unless you hack up your version of
windows with /3gb in which case it would be 3 :)

Except that I believe there's a limitation that any object in .NET can
be at most 2GB anyway. Besides which, the string.Length property can
only go up to int.MaxValue/2 (because the top 2 bits are used for extra
information) which means a maximum of 1G characters (2GB).

I seem to remember there's something else which knocks it down by a few
characters too (other than the object overhead, of course).

As always with this discussion, it's worth noting that all this means
you'll run into other problems before you run into the limit of string
lengths :)

Jon
 
T

tshad

Jon Skeet said:
Except that I believe there's a limitation that any object in .NET can
be at most 2GB anyway. Besides which, the string.Length property can
only go up to int.MaxValue/2 (because the top 2 bits are used for extra
information) which means a maximum of 1G characters (2GB).

I seem to remember there's something else which knocks it down by a few
characters too (other than the object overhead, of course).

As always with this discussion, it's worth noting that all this means
you'll run into other problems before you run into the limit of string
lengths :)

True.

I would not even come close to these limits. I just wanted to make sure
there wasn't a smaller limit such as 32k or 64k.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top