Import-SPWeb invalid date/time data - sharepoint-2010

I have exported a SharePoint 2010 document library using SharePoint Central Administration to create a backup cmp file. This was all good. The library contains a date/time field called EnrolmentDate. There are 6000 rows in total and about 2000 of these rows have an EnrolmentDate value of 1/1/1900.
When I try and use Import-SPWeb to import into another site, only 4000 rows are imported. The rows containing the enrollment date 1/1/1900 do not import and are generating an error in the import log file which states:
Error: Invalid date/time value. A date/time field contains invalid data
I was under the impression that the range for the date/time data in SharePoint type starts at 1/1/1900. These values are in the original list so not sure why they won't import?
I have checked the sites regional settings and they are the same. It seems no one else in the history of SharePoint has encountered this error as I can't find it online anywhere.
Any help appreciated.

Related

SSMS - Importing into nvarchar(max) still giving truncate errors

I'm using SSIS to import an Excel table into SQL Server.
The field in the SQL Server table is set as nvarchar(max) but it still gives me Truncate Error.
The column that I want to import can have any number of characters, it could be 1 or it could be 10,000. It's a free-text filed without any limitations.
Go into the Advanced settings of your Excel Source Component, and manually set the length of the Output columns.
SSIS samples your data to get an idea of each column. It will use the max length of the sample to determine the "proper" field size. Of course this causes constant issues.
Can you add something to order your data to make the longest first?
ORDER BY LEN(LongFIELD) DESC
Check out StackExchange for more info:
Text was truncated or one or more characters had no match in the target code page When importing from Excel file

Importing Excel File into SQL Server 2012

I'm having the hardest time importing an Excel file with approx 300 records into SQL server without getting errors. I am getting an error that text will be truncated, but I checked and the max character count in that field is 520 characters. That should be fine importing into a Varchar(MAX) field. Any recommendations on best procedures for importing Excel files (just one tab) into SQL Server 2012? I have tried everything I can think of including editing mappings, etc, and still cannot get it to properly import.
The truncation error is in the import 'source' settings. In the mappings screen choose 'Edit Mappings', then you can adjust the field size. There's also an 'Edit SQL' on the mapping screen where you can wrap your fields and cast them to the correct size
select cast(col1 as varchar(50))...
Consider exporting the data to csv and then do the import. I always have formatting issues with Excel, especially with dates.

Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column

I'm trying to insert a large CSV file (several gigs) into SQL Server, but once I go through the Import Wizard and finally try to import the file I get the following error report:
Executing (Error)
Messages
Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data
conversion for column ""Title"" returned status value 4 and status
text "Text was truncated or one or more characters had no match in the
target code page.".
(SQL Server Import and Export Wizard)
Error 0xc020902a: Data Flow Task 1: The "Source -
Train_csv.Outputs[Flat File Source Output].Columns["Title"]" failed
because truncation occurred, and the truncation row disposition on
"Source - Train_csv.Outputs[Flat File Source Output].Columns["Title"]"
specifies failure on truncation. A truncation error occurred on the
specified object of the specified component.
(SQL Server Import and Export Wizard)
Error 0xc0202092: Data Flow Task 1: An error occurred while processing
file "C:\Train.csv" on data row 2.
(SQL Server Import and Export Wizard)
Error 0xc0047038: Data Flow Task 1: SSIS Error Code
DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Source - Train_csv
returned error code 0xC0202092. The component returned a failure code
when the pipeline engine called PrimeOutput(). The meaning of the
failure code is defined by the component, but the error is fatal and
the pipeline stopped executing. There may be error messages posted
before this with more information about the failure.
(SQL Server Import and Export Wizard)
I created the table to insert the file into first, and I set each column to hold varchar(MAX), so I don't understand how I can still have this truncation issue. What am I doing wrong?
In SQL Server Import and Export Wizard you can adjust the source data types in the Advanced tab (these become the data types of the output if creating a new table, but otherwise are just used for handling the source data).
The data types are annoyingly different than those in MS SQL, instead of VARCHAR(255) it's DT_STR and the output column width can be set to 255. For VARCHAR(MAX) it's DT_TEXT.
So, on the Data Source selection, in the Advanced tab, change the data type of any offending columns from DT_STR to DT_TEXT (You can select multiple columns and change them all at once).
This answer may not apply universally, but it fixed the occurrence of this error I was encountering when importing a small text file. The flat file provider was importing based on fixed 50-character text columns in the source, which was incorrect. No amount of remapping the destination columns affected the issue.
To solve the issue, in the "Choose a Data Source" for the flat-file provider, after selecting the file, a "Suggest Types.." button appears beneath the input column list. After hitting this button, even if no changes were made to the enusing dialog, the Flat File provider then re-queried the source .csv file and then correctly determined the lengths of the fields in the source file.
Once this was done, the import proceeded with no further issues.
I think its a bug, please apply the workaround and then try again: http://support.microsoft.com/kb/281517.
Also, go into Advanced tab, and confirm if Target columns length is Varchar(max).
The Advanced Editor did not resolve my issue, instead I was forced to edit dtsx-file through notepad (or your favorite text/xml editor) and manually replace values in attributes to
length="0" dataType="nText" (I'm using unicode)
Always make a backup of the dtsx-file before you edit in text/xml mode.
Running SQL Server 2008 R2
Goto Advanced tab----> data type of column---> Here change data type from DT_STR to DT_TEXT and column width 255. Now you can check it will work perfectly.
Issue:
The Jet OLE DB provider reads a registry key to determine how many rows are to be read to guess the type of the source column.
By default, the value for this key is 8. Hence, the provider scans the first 8 rows of the source data to determine the data types for the columns. If any field looks like text and the length of data is more than 255 characters, the column is typed as a memo field. So, if there is no data with a length greater than 255 characters in the first 8 rows of the source, Jet cannot accurately determine the nature of the data type.
As the first 8 row length of data in the exported sheet is less than 255 its considering the source length as VARCHAR(255) and unable to read data from the column having more length.
Fix:
The solution is just to sort the comment column in descending order.
In 2012 onwards we can update the values in Advance tab in the Import wizard.

generated excel from SSIS but getting quote in every column?

I have generated and excel from SSIS package successfully.
But every column is having extra ' (quote) mark why is it so?
My source sql table is like below
Name price address
ashu 123 pune
jkl 34 UK
In my sql table i took all column as varchar(50) datatype.
In Excel Manager when it is going to create table
Excel Destination took all column as same varchar(50) datatype.
And in Data Flow I have used Data Conversion transformation to prevent unicode conversion error.
Please advice where i need to change to get the clear columns in excel file.
You could create a template Excel file in which you have specified all the column types (change to Text from General) and headers you will need. Store it in a /Template directory and have copy it over to where you will need it from within the SSIS package.
In your SSIS package:
Use Script Component to copy Excel Template file into directory of choice.
Programatically change its name and store the whole filepath in a variable that will be used in your corresponding Data Flow Task.
Use Expression Builder for your Excel Connection Manager. Set the ExcelFilePath to be retrieved from your variable.
the single quote or apostrophe is a way of entering any data (in Excel) and ensure it is treated as text so numbers with leading zeros or fractions are not interpreted by Excel as numeric or dates.
a NJ zip code for instance 07456 would be interpreted as 7456 but by entering it as '07456 it keeps its leading zero (please note that numbers in your example are left aligned, like text is)
I guess SSIS is adding the quotes because your data is of VARCHAR type
First, define the field types for your excel destination in SSIS, any non-text fields will format properly without the '. Then, add a derived column transformation between your source and destination, and use a replace statement for any text columns.
Should be:
(REPLACE(Column1, "'","")
This caused me major problems! So I completed the following:
You can change the excel version to 'Microsoft Excel 4.0' within the excel connection manager in your SSIS package.
Then within excel follow Options > Trust Center > Trust Center Settings > File Block Settings > Untick the 'Open' checkbox for 'Excel 4 workbooks' and 'sheets'.
It is a particular problem when using the Excel destination, at least with older versions of SSIS anyway. To answer the why question, there is this in the Microsoft documentation:
The following behaviors of the Jet provider that is included with the Excel driver can lead to unexpected results when saving data to an Excel destination.
Saving text data. When the Excel driver saves text data values to an Excel destination, the driver precedes the text in each cell with the single quote character (') to ensure that the saved values will be interpreted as text values. If you have or develop other applications that read or process the saved data, you may need to include special handling for the single quote character that precedes each text value.
Taken from https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms137643(v=sql.105)

Error importing to SQL Server 2008R2 from Excel 2010

I am using the SQL Server Import and Export Wizard to try to import a particular xlsx spreadsheet into an existing table in SQL. The existing table contains a sub-set of the columns in the spreadsheet and I am ignoring the many columns that don't match.
The spreadsheet has 123 columns and 238 lines of data.
Initially when I was importing the spreadsheet the wizard was hanging on 'Executing' and I had to kill the process. Something I have never come across before.
After copy and pasting the data into a new spreadsheet it is now coming up with the following error:
Error 0xc020901c: Data Flow Task 1: There was an error with output column "Confidentiality Clause Comments" (108) on output "Excel Source Output" (9). The column status returned was: "Text was truncated or one or more characters had no match in the target code page.".
(SQL Server Import and Export Wizard)
Error 0xc020902a: Data Flow Task 1: The "output column "Confidentiality Clause Comments" (108)" failed because truncation occurred, and the truncation row disposition on "output column "Confidentiality Clause Comments" (108)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
(SQL Server Import and Export Wizard)
What I am confused about it, the column "Confidentiality Clause Comments" is one of the columns being ignored - it is not being imported into the database!
I have tried setting "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Jet 4.0\Engines\Excel\TypeGuessRows" to both 0 and higher numbers like 238 and 1000 to increase the sample size. (Although the table does already exist with fields large enough for the data being imported). I also have the "On Truncation (global)" and "On Error (global)" set to Ignore (but this setting seems to be 'ignored').
I have also tried importing the data into a new table, and get the same truncation error message (but on different fields dependant on the data sort).
I thought about importing as a CSV file but there are embedded comma's in many of the fields and it completely messed the data up.
Any ideas on how to get data imported? I have spent over 3 hours on this already, and have got nowhere.
Thanks,Steve
Instead of CSV, you could save as Text (Tab delimited) (*.txt) - that way you won't encounter the comma problem.
Also, if you only need to do this once, and because the dataset is not exactly huge, I'd consider just copying from excel and pasting directly into sql server management studio.