I've set up a SQL Server database on Amazon RDS and am using NodeJS and an NPM package called MSSQL to handle connecting and manipulating data. Because this package has some kind of built in mapper that assumes I'm passing a Javascript Date if the field in question is Datetime, I instead declared those fields as NVarChar without length, but on the larger table (Contact) with hundreds of fields this works fine; I inserted over a million rows like this.
The only difference I can spot is that the Contact table has ANSI_PADDING. In addition, I'm pretty sure all string dates coming from the source DB are in a format like this:
2015-03-26T18:09:48.000Z
And this is the message received from trying to bulk insert on the SOMETASK table (didn't say which field):
RequestError: Conversion failed when converting date and/or time from character string.
In Node, I'm using a map of fields to MSSQL Types. Any datetime field on either table is declared like so:
"CREATEDDATE": { t: sql.NVarChar(), o: { nullable: true } },
(Which gets iterated over and used to instantiate Column objects for the MSSQL package to use with bulk inserts. FYI, it also seems like you -must- have the columns declared in Node in the same order as they are in the DB)
Also, here's that MSSQL package: http://ift.tt/1JCzI06
Here's an excerpt from the sql script used to create the two tables in question:
/****** Object: Table [dbo].[CONTACT] Script Date: 6/10/2015 8:14:54 AM ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [dbo].[CONTACT](
[ID] [nvarchar](18) NOT NULL,
[CREATEDDATE] [datetime] NULL,
[LASTMODIFIEDDATE] [datetime] NULL,
[SYSTEMMODSTAMP] [datetime] NULL,
[TIMESTAMP] [timestamp] NULL,
[etc....about 400 fields in total but I only included the
datetime ones that appear in both]
CONSTRAINT [PK_CONTACT] 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]
SET ANSI_PADDING OFF
/****** Object: Table [dbo].[SOMETASK] Script Date: 6/10/2015 8:14:54 AM ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE TABLE [dbo].[SOMETASK](
[ID] [nvarchar](18) NOT NULL,
[OWNERID] [nvarchar](18) NULL,
[ISDELETED] [int] NULL,
[NAME] [nvarchar](80) NULL,
[CREATEDDATE] [datetime] NULL,
[CREATEDBYID] [nvarchar](18) NULL,
[LASTMODIFIEDDATE] [datetime] NULL,
[LASTMODIFIEDBYID] [nvarchar](18) NULL,
[SYSTEMMODSTAMP] [datetime] NULL,
[RICH_NOTE] [ntext] NULL,
[TASK_ID] [nvarchar](18) NULL,
[TIMESTAMP] [timestamp] NULL,
CONSTRAINT [PK_SOMETASK] 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]
Aucun commentaire:
Enregistrer un commentaire