Hello,
I am trying to import data from csv to a sql server table (2008 R2 SE edition of sqlserver) with an ssis package. The data I am trying to import is from a website form that gets saved to a csv file. Here is the table DDL:
CREATE TABLE [dbo].[FormData](
[ID] [int] IDENTITY(1,1) NOT NULL,
[CreatedAt] [datetime] NULL,
[FirstName] [nvarchar](60) NULL,
[LastName] [nvarchar](60) NULL,
[Title] [nvarchar](60) NULL,
[BusinessName] [nvarchar](60) NULL,
[TypeOfBusiness] [nvarchar](60) NULL,
[EmailAddress] [nvarchar](60) NULL,
[PhoneNumber] [nvarchar](24) NULL,
[PhoneExtension] [nvarchar](20) NULL,
[TypeOfInquiry] [nvarchar](60) NULL,
[YourInterests] [nvarchar](4000) NULL,
CONSTRAINT [PK_FormData] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[FormData] ADD CONSTRAINT [DF_CreateDate_GetdateValue] DEFAULT (getdate()) FOR [CreatedAt]
GO
My ssis package does the inserts from csv to table without errors if all fields have values in the csv file. However if someone doesnt have a phoneextension and fill out the form and submit without entering data for this field then my ssis package fails
with the following error:
[Flat File Source [1]] Error: Data conversion failed. The data conversion for column ""Phone Extension"" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
[Flat File Source [1]] Error: The "output column ""Phone Extension"" (118)" failed because truncation occurred, and the truncation row disposition on "output column ""Phone Extension"" (118)" specifies
failure on truncation. A truncation error occurred on the specified object of the specified component.
I am providing with sample data below for which the insert failed:
Createdat,First,Last,"Company Name","Type of Organization","Enter Email",Phone,"What's Your Interest?",Title,"Phone Extension"
"2016-04-12 00:51:39",Ben,Charles,"Thai Massage",Business,newoilmassage@yahoo.com,"(123) 222-4444","Want to send out general messages to massage lovers daily",,,,,
I am converting data according the column sizes in the table and they are all DT_WSTR except for date as the date uses a default constraint
Mapping is as shown:
First-->FirstName, Lasr-->LastName, companyname-->businessName,Typeoforganization-->Typeofbusiness,enteremail-->emailaddress,Phone-->phonenumber,What's Your Interest?-->yourinterests,Title-->title,"Phone
Extension"-->phoneextension
A csv file with successfull insert looks like this:
Createdat,First,Last,"Company Name","Type of Organization","Enter Email",Phone,"Phone Extension","What's Your Interest?",Title
"2016-04-11 18:21:59",Adams,Chris,testdata,Business,test@test.com,"(123) 456-7890",1111,"this is just for test",,,,
How can I fix this error and let inserts run normally?
Thanks a ton