ASP.NET VB SqlBulkCopy String or binary data would be truncated - sql

I'm trying to use SqlBulkCopy to upload a data table into SQL Server.
I'm getting this error:
String or binary data would be truncated.
I'm using
sqlBulkcopy.WriteToServer(dtCustom)
The SQL Server column is defined as nvarchar(50)
I changed the column to nvarchar(150) and same problem
This line is causing the problems with the import:
Enter the Location of Inspection
The line is 32 characters
If I remove "on" then it works and imports.
So what's the deal with a SQL Server table column defined as nvarchar(50) and 32 characters for data going into it?
Any ideas?

The columns have to be mapped. Even though the datatable has the same column names as the SQL table - in the asp.net vb coding you still have to do column mappings.

Related

SSIS error when adding excel destination

I have a SSIS package with data in a SQL Server 2012 table have added an Excel destination and get the error
There is no sufficient information about mapping ssis types to types of the selected .net data provider. As a result you may need to modify the default types of the SQL statement on the next screen
Code:
CREATE TABLE `Excel Destination`
(
`name` VARCHAR(50),
`date` DATETIME
)
It doesn't like the 'name' column I have added a data conversion task but the 'name' column is already set to unicode string. So I'm not sure why I get message about converting between non unicode and unicode?
Any advice would be welcome.
Please check, This error is because your sheet is empty and there are no columns defined in it. you have to write the names of the column in the first row the target sheet.

SQL Developer Data is not compatible with column definition

I'm trying to insert data into my table but I am receiving this error:
"SQL Developer Data is not compatible with column definition or is not available for a nut nullable column"
The column that is getting this error has data of the form 7391DBDF-40D5-E523-80C2-3863BB43AC67.
I believe this is a uniqueidentifer but but I'm not sure how one would insert this datatype into SQL Developer.
nvm: got it. Use Varchar
Same error importing good data into a number column with SQLDeveloper, problem was not specifying precision and scale on the column.
Solved by setting size to 28,0.

[Excel Destination [28]] Error: An error occurred while setting up a binding for the column. The binding status was "DT_NTEXT"

I'm working on ssis package which exports data from SQL Server to Excel. I had a problem converting non-unicode to unicode string data types. So I created a derived Column task and converted to Unicode string [DT_WSTR] 4 columns which have a type Varchar(40) in SQL Server table. It worked with these columns. But I also have a Description column of type varchar(max) and I tried to convert it to Unicode text stream [DT_NTEXT]. It did not work.
If your source is SQL Server (as you said), you can convert it directly in your SQL Query
SELECT
CONVERT(NVARCHAR(40), 'att1')
,CONVERT(NTEXT, 'att2')
Convert your VARCHAR into NVARCHAR
Convert your TEXT into NTEXT
it's faster.
P.S. To test it (Do not forget to delete or reset your previous OLE DB Input component) -> It will be forced to reevaluate your datatype
Does it help you?
The only thing that worked was to cast a Description column in Stored Procedure as varchar(1000). I checked the max length of this field and it was about 300 characters. So I made it varchar(1000) and in Derived column Unicode string [DT_WSTR]. This was a workaround, but I still want to know how to make it in ssis package without converting data type in Stored Procedure.

Can't convert String to Numeric/Decimal in SSIS

I have five or six OLE DB Sources with a String[DT_STR], with a length of 500 and 1252 (Latin) as Code Page.
The format of the column is like 0,08 or 0,10 etc etc. As you can see, it is separated with a comma.
All of them are equal except one of them. In this one source, I have a POINT as separation. On this it is working when I set the Data Type in the advanced editor of the OLE DB Source. On another (with comma separated) it is also working, if I set the Data Type in the advanced editor of the OLE DB Source. BUT the weird thing is, that it isn't working with the other sources although they are the same (sperated with comma).
I tested Numeric(18,2) and decimal(2).
Another try to solve the problem with the conversion task and/or the derived column task, failed.
I'm using SQL Server 2008 R2
Slowly, I think SSIS is fooling me :)
Has anyone an idea?
/// EDIT
Here a two screens:
Is working:
click
Isn't working:
click
I would not set the Data Type in the Advanced Editor of the OLE DB Source. I would convert the data in the SQL Code of the OLE DB Source, or in a Script Transformation e.g. using Decimal.TryParse , which would update a new column.
SSIS is unbeleivably fussy over datatypes and trying to mess with its internals is not productive.
Check that there are any spaces in between the commas, so that the SSIS is throwing an error trying to convert the blank space to a number. A blank space does not equal nothing in between spaces.
Redirect error rows and output the data to a file. Then you can examine the data that is being rejected by the SSIS and determine why it's causing error.
Reason for the error
1) Null’s are not properly handled either in the destination database or during SSIS package creation. It is quite possible that the source contains a null database but the destination is not accepting the NULL data leading to build generate above error.
2) Data types between source and destination does not match. For example, source column has varchar data and destination column have an int data type. This can easily generate above error. There are certain kind of datatypes which will automatically convert to another data type and will not generate the error but there are for incompatible datatypes which will generate The value could not be converted because of a potential loss of data. error.
The Issue arises when there is unhandled space or null. I have worked around using the Conditional (Ternary) Operator which checks the length:
LEN(TRIM([Column Name])) >= 1 ? (DT_NUMERIC,38,8)[Column Name] : 0

VB.NET and SQL INSERT INTO; data is truncated

I use VB.NET Studio Express 2012 to read a filestream into SQL Server Express. The database and table are created fine, most records load without error using .ExecuteNonQuery INSERT INTO, but some records I get the error:
String or binary data would be truncated.
Originally this was correct, because the column was only 20 characters and the data was between 22-25 on the failing records. I have changed the table so the column now is 30 char, but the error is still the same. I dropped the database and recreated it, but still the same problem.
Does VB keep info on field length somewhere?
May be some spaces are present before or after your string,you can use Trim() function and then try to insert.Trim function will remove extra spaces placed before and after you string.