Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1014
  • Last Modified:

Do .NET tableadapters truncate strings?

Hiya,
I'm having trouble figuring out the following so would appreciate some help...
I have a TableAdapter set up that includes an insert query to insert a lot of text data into a field in my database.  However, it seems that the string is truncated to 1024 characters every time.  I've checked external factors (IIS, sceurity, etc) and ruled those out - not least because another program using the same services CAN post >1024 chars - so that leaves my code.

I've checked that the data is not truncated in my code (it's stored as a string) and it is not.
The field is set up as a system.string in the tableadapter with a max length of 2147483647
The field is set up in my DB as a text

Why would the data get truncated?  Is there an issue in .NET (v2 by the way) or in what I've done?  Any advice greatly appreciated...
0
markg28
Asked:
markg28
  • 12
  • 6
1 Solution
 
pivarCommented:
Hi,

How do you see that text is 1024 chars? If it's in query analyzer/SSMS you may have to increase maximum chars displayed in a column or change to grid view which usually display more characters.

/peter
0
 
markg28Author Commented:
Hi Peter,
I use SQL Mgmt Studio (Express) to view the DB contents.  I've also just viewed the results using a new query window.
Interesting point though - hadn't considered that it could be the view...

Mike.
0
 
markg28Author Commented:
[edit] FWIW the field in the DB is actually 'ntext' not 'text'
0
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
pivarCommented:
Choose Tools/Options in the menu. Then choose Query Results/SQL Server/Results to text, change the Maximum number of characters... as needed. Max is 8192 though.
0
 
markg28Author Commented:
Well... this made no difference :-) Not least becuase it was set to 256 and 1024 chars were still showing in my grid (which is set to 65535.

I will create a test program in ASP that will display the contents of the tbale - as that shouldn't be restricted to any characters surely?  That will confirm that it isn't in the display - as I'm pretty sure it isn't that unfortunately (would be an easy fix if it were).
0
 
pivarCommented:
Yes, that could confirm it. Can you show us your insertioncode?
0
 
markg28Author Commented:
OK, test code show truncated text from Db, so safe to assume that it's stored that way.

Code as below - *valueIRV* is the field that's being truncated - as described above, it's set in my TableAdapter as a system.string with maxlength of 2147483647.  I haven't delved into the data layer designer.vb - should I?

Dim qIRVUpdate As New tdDALTableAdapters.Candidates3_IRVTableAdapter
                    Dim qIRVdata As tdDAL.Candidates3_IRVDataTable = qIRVUpdate.GetIRVData(CandBlindID, InstrumentID, iLang, CurrentSectionName)
qIRVUpdate.InsertIRVData(tdAccountID, CandBlindID, InstrumentID, iLang, CurrentSectionName, itemIRV, valueIRV, Now())

Open in new window

0
 
pivarCommented:
I tried to mimic your code and it works well. Are you sure valueIRV is not truncated before InsertIRVData? Where does the text come from?
Also I do believe maxlength if you got ntext should be 1073741823.
How does the insertstatement look like in InsertIRVdata?
0
 
markg28Author Commented:
The text comes from the FORM:

Dim valueString As String = ""
valueString = Request.Form(aryItemText(i))  ' where aryItemText(i) is the name of the form element

I've verified that this is the full string by writing it to a session object, just before the insert command - which showed the full text.

The InsertIRVdata query is as follows:
INSERT INTO [Candidates3_IRV] ([AccountID], [CandBlindID], [InstrID], [Lang], [SectionName], [ItemIRV], [ValueIRV], [DateCompleted]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)

Not sure about the maxlength of ntext - obviously it's all auto-created by .NET as the tableadapter was created.  

Thinking back, the DB field may not ahve been ntext historically and, although I've recrated the adapter since, could it be that it's still reverting back to the previous settings (despite showing a maxlength that should cope)?  Would this be in the designer.vb file?  Looked through and it seems to be set as per shown, but you never know...
0
 
markg28Author Commented:
[bump]
Can anyone help me please?!?!
0
 
PUBANDCommented:
Are you sure it is not complete in the DB?  Try something like this:
declare @mytext varcar(5000)
select @mytext = textcol from yourtable
print @mytext
0
 
markg28Author Commented:
Quite sure.  Just ran the SQL you suggested and got the text truncated at 1024 again.  Did the same by creating a test ASP page to output the DB contents also.
It must be how the data is inserted, I just can't figure out why it would truncate it...
0
 
pivarCommented:
Have you tried changing the maxlength? I'm a C# guy so I'm not familiar with VB but you should be able to change that in designer?
0
 
markg28Author Commented:
Cheers - I guess I could change the maxlength - hadn't really thought as it was showing that it was plenty big enough.  Of course, that's assuming there isn't something funny going on - will give it a go on Monday and report back - much appreciated.
0
 
markg28Author Commented:
Well... reporting back - changed the maxlength to 1,999,999,999 and still have same issue of data string being truncated at 1024chars.  Verified by both DB check and also through ASP (not ASP.NEt in case the issue is specific to .NET) code to connect to DB and show contents.

Hmm.  So, I guess what you're saying is that there isn't a known limit and there shouldn't be a problem posting this much data?

Will rebuild the table adapter and see if this helps, although looking through the designr.vb file, it all seems to be defined correctly.

Feel free to supply any futher top tips!!!  Thanks.
0
 
pivarCommented:
Try 1073741823, since ntext/nchar uses 2 bytes per char compared to text/char which uses 1 byte and 2147483647(maximum for text)/2=1073741823. This is a longshot, but worth trying I believe. No there should not be a maximum of 1024 chars för ntext. Otherwise rebuilding the adapter from scratch would probably be easier compared to search for this type error.
0
 
markg28Author Commented:
Nope, same again; truncated.
OK, will get on and rebuild the adapter - cheers
0
 
markg28Author Commented:
Whoo-hoo, it works!!!  Rebuilding the tableadapter did it - it may have taken a while, but the definition must have been all screwy in my .xsd.  Many thanks for your help everyone, very much appreciated indeed!
0
 
markg28Author Commented:
Thank you for hanging in there with me!!!
0
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.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 12
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now