Avatar of andreyATCr
andreyATCr
 asked on

Bulk insert truncates string to 255 characters

I am importing a TXT (tab) file into an SQL table.

Destination table is well over Varchar(1000) char in all the columns and value of that particular column has 800+ chars
So it looks like everything working fine, table has all the right data, but one column which usually has large string always truncated to 255

I'm using regular WriteToServer bcp command in the code
.NET ProgrammingMicrosoft SQL ServerMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
andreyATCr

8/22/2022 - Mon
Bob Learned

Are you importing the text file into a DataTable, and calling SqlBulkCopy.WriteToServer with that?

Bob
andreyATCr

ASKER
exactlly
andreyATCr

ASKER
Code:

                                OdbcDataAdapter da = new OdbcDataAdapter("Select * FROM " + name, conn);
                               
                                //Retrieve the rows into a dataset from the text file
                                infoImportds = new DataSet();
                                da.Fill(infoImportds, "SourceTable");

DataTable infoImportdt = infoImportds.Tables[0];

sbc = new SqlBulkCopy(AppHelper.GetConfigValue(AppConstants.CNST_CONFIG_CONNECTION_STRING));

  sbc.BulkCopyTimeout = 900;
  sbc.WriteToServer(infoImportdt);
  sbc.Close();
 
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Bob Learned

I don't think that the problem is with the SqlBulkCopy, but with the ODBC handling the text file.

Do you know how to check the length of the defined column for a DataTable?

Bob
andreyATCr

ASKER
I suspected this was a problem
I dont know how to check that
It's strange that ODBC limits this string length to 255
BTW, i'm using schema.ini to setup a few things
ColNameHeader=True
Format=TabDelimited
MaxScanRows=0
CharacterSet=ANSI
ASKER CERTIFIED SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
andreyATCr

ASKER
Are you saying that if i do NOT specify width for the column in schema.ini for that particular field of my TAB delimited file, it will default to 255 max?
Thank you
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Bob Learned

I do believe that I have seen 255 as a max, but for what I don't know.  It would make sense, since 255 is the max size for a byte.

Bob
andreyATCr

ASKER
So i modified my code to specify all columns in schema.ini and set width of each to over 1000
Unfortunately the result hasnt changed
Data is being imported, but still 255
:(
andreyATCr

ASKER
I found solution
I used Memo Width vs. Text Width in ini file and it worked
Thank you for your help, you did lead me into it
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck