Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

bulk insert and openrowset

 
   Database Help (Home) -> Programming RSS
Next:  HOW TO: Use Parameters with DATEADD  
Author Message
JTL

External


Since: Jul 25, 2007
Posts: 12



(Msg. 1) Posted: Wed Jan 10, 2007 3:49 pm
Post subject: bulk insert and openrowset
Archived from groups: microsoft>public>sqlserver>programming (more info?)

i'm having the strangest problem right now and can't seem to figure out
what's going on- here's the deal:

i'm trying to use the openrowset command, in combination with the bulk
insert command to load data from a text file into sql server. the text file
im using has a field that can have a length when i execute the following, i
receive a "Bulk load data conversion error (truncation) ":

INSERT INTO tTempImport
SELECT *
FROM OPENROWSET(
BULK 'E:\temp\myimportfile.txt',
FORMATFILE = 'E:\temp\myformatfile.fmt'
) as t1


however, this works just fine:

BULK INSERT tTempImport
FROM 'E:\temp\myimportfile.txt'
WITH (FORMATFILE = 'E:\temp\myformatfile.fmt')


** the field in the import file that is causing the error has a length of
13988 characters
** the "Bulk load data conversion error (truncation) " error has nothing to
do with the insert, as i get the same thing when just running the select *
from openrowset... portion

*** so what is it about the select * from openrowset command, that is
causing sql server to do some sort of conversion on the data in the text
file???

--========================================================
here are the contents of my format file:
--========================================================
9.0
8
1 SQLCHAR 0 0 "\"" 0 "" ""
2 SQLCHAR 0 0 "|" 2 col2
SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 0 "|" 3 col3
SQL_Latin1_General_CP1_CI_AS
4 SQLCHAR 0 0 "|" 4 col4
SQL_Latin1_General_CP1_CI_AS
5 SQLCHAR 0 0 "|" 5 col5
SQL_Latin1_General_CP1_CI_AS
6 SQLCHAR 0 0 "|" 6 col6
SQL_Latin1_General_CP1_CI_AS
7 SQLCHAR 0 0 "|" 7 col7
SQL_Latin1_General_CP1_CI_AS
8 SQLCHAR 0 0 "|\"\r\n" 8 col8
SQL_Latin1_General_CP1_CI_AS


--========================================================
--here is the table definition for tTempImport:
--========================================================
CREATE TABLE [dbo].[tTempImport](
[id] [int] IDENTITY(1,1) NOT NULL,
[col2] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[col3] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[col4] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[col5] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[col6] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[col7] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[col8] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_tTempImport] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


TIA!!!
jt

 >> Stay informed about: bulk insert and openrowset 
Back to top
Login to vote
Zekske

External


Since: Oct 04, 2007
Posts: 2



(Msg. 2) Posted: Thu Jan 11, 2007 2:06 am
Post subject: RE: bulk insert and openrowset [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Did you enable the openrowset option in the Surface Area Configuration for
Features?

"JTL" wrote:

> i'm having the strangest problem right now and can't seem to figure out
> what's going on- here's the deal:
>
> i'm trying to use the openrowset command, in combination with the bulk
> insert command to load data from a text file into sql server. the text file
> im using has a field that can have a length when i execute the following, i
> receive a "Bulk load data conversion error (truncation) ":
>
> INSERT INTO tTempImport
> SELECT *
> FROM OPENROWSET(
> BULK 'E:\temp\myimportfile.txt',
> FORMATFILE = 'E:\temp\myformatfile.fmt'
> ) as t1
>
>
> however, this works just fine:
>
> BULK INSERT tTempImport
> FROM 'E:\temp\myimportfile.txt'
> WITH (FORMATFILE = 'E:\temp\myformatfile.fmt')
>
>
> ** the field in the import file that is causing the error has a length of
> 13988 characters
> ** the "Bulk load data conversion error (truncation) " error has nothing to
> do with the insert, as i get the same thing when just running the select *
> from openrowset... portion
>
> *** so what is it about the select * from openrowset command, that is
> causing sql server to do some sort of conversion on the data in the text
> file???
>
> --========================================================
> here are the contents of my format file:
> --========================================================
> 9.0
> 8
> 1 SQLCHAR 0 0 "\"" 0 "" ""
> 2 SQLCHAR 0 0 "|" 2 col2
> SQL_Latin1_General_CP1_CI_AS
> 3 SQLCHAR 0 0 "|" 3 col3
> SQL_Latin1_General_CP1_CI_AS
> 4 SQLCHAR 0 0 "|" 4 col4
> SQL_Latin1_General_CP1_CI_AS
> 5 SQLCHAR 0 0 "|" 5 col5
> SQL_Latin1_General_CP1_CI_AS
> 6 SQLCHAR 0 0 "|" 6 col6
> SQL_Latin1_General_CP1_CI_AS
> 7 SQLCHAR 0 0 "|" 7 col7
> SQL_Latin1_General_CP1_CI_AS
> 8 SQLCHAR 0 0 "|\"\r\n" 8 col8
> SQL_Latin1_General_CP1_CI_AS
>
>
> --========================================================
> --here is the table definition for tTempImport:
> --========================================================
> CREATE TABLE [dbo].[tTempImport](
> [id] [int] IDENTITY(1,1) NOT NULL,
> [col2] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> [col3] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> [col4] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> [col5] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> [col6] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> [col7] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> [col8] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> CONSTRAINT [PK_tTempImport] PRIMARY KEY CLUSTERED
> (
> [id] ASC
> )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
> ) ON [PRIMARY]
>
>
> TIA!!!
> jt
>
>
>
>
>

 >> Stay informed about: bulk insert and openrowset 
Back to top
Login to vote
JTL

External


Since: Jul 25, 2007
Posts: 12



(Msg. 3) Posted: Thu Jan 11, 2007 11:16 am
Post subject: Re: bulk insert and openrowset [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

yes i did-


"Zekske" wrote in message

> Did you enable the openrowset option in the Surface Area Configuration for
> Features?
>
> "JTL" wrote:
>
>> i'm having the strangest problem right now and can't seem to figure out
>> what's going on- here's the deal:
>>
>> i'm trying to use the openrowset command, in combination with the bulk
>> insert command to load data from a text file into sql server. the text
>> file
>> im using has a field that can have a length when i execute the
>> following, i
>> receive a "Bulk load data conversion error (truncation) ":
>>
>> INSERT INTO tTempImport
>> SELECT *
>> FROM OPENROWSET(
>> BULK 'E:\temp\myimportfile.txt',
>> FORMATFILE = 'E:\temp\myformatfile.fmt'
>> ) as t1
>>
>>
>> however, this works just fine:
>>
>> BULK INSERT tTempImport
>> FROM 'E:\temp\myimportfile.txt'
>> WITH (FORMATFILE = 'E:\temp\myformatfile.fmt')
>>
>>
>> ** the field in the import file that is causing the error has a length of
>> 13988 characters
>> ** the "Bulk load data conversion error (truncation) " error has nothing
>> to
>> do with the insert, as i get the same thing when just running the select
>> *
>> from openrowset... portion
>>
>> *** so what is it about the select * from openrowset command, that is
>> causing sql server to do some sort of conversion on the data in the text
>> file???
>>
>> --========================================================
>> here are the contents of my format file:
>> --========================================================
>> 9.0
>> 8
>> 1 SQLCHAR 0 0 "\"" 0 "" ""
>> 2 SQLCHAR 0 0 "|" 2 col2
>> SQL_Latin1_General_CP1_CI_AS
>> 3 SQLCHAR 0 0 "|" 3 col3
>> SQL_Latin1_General_CP1_CI_AS
>> 4 SQLCHAR 0 0 "|" 4 col4
>> SQL_Latin1_General_CP1_CI_AS
>> 5 SQLCHAR 0 0 "|" 5 col5
>> SQL_Latin1_General_CP1_CI_AS
>> 6 SQLCHAR 0 0 "|" 6 col6
>> SQL_Latin1_General_CP1_CI_AS
>> 7 SQLCHAR 0 0 "|" 7 col7
>> SQL_Latin1_General_CP1_CI_AS
>> 8 SQLCHAR 0 0 "|\"\r\n" 8 col8
>> SQL_Latin1_General_CP1_CI_AS
>>
>>
>> --========================================================
>> --here is the table definition for tTempImport:
>> --========================================================
>> CREATE TABLE [dbo].[tTempImport](
>> [id] [int] IDENTITY(1,1) NOT NULL,
>> [col2] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
>> [col3] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
>> [col4] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
>> [col5] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
>> [col6] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
>> [col7] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
>> [col8] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
>> CONSTRAINT [PK_tTempImport] PRIMARY KEY CLUSTERED
>> (
>> [id] ASC
>> )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
>> ) ON [PRIMARY]
>>
>>
>> TIA!!!
>> jt
>>
>>
>>
>>
>>
 >> Stay informed about: bulk insert and openrowset 
Back to top
Login to vote
Zekske

External


Since: Oct 04, 2007
Posts: 2



(Msg. 4) Posted: Fri Jan 12, 2007 7:29 am
Post subject: Re: bulk insert and openrowset [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Check the NTFS rights on the file.
I'm not sure but I believe the bulk insert uses the SQL-server agent account
but the open rowset uses the user credentials from the user who is executing
the query.



"JTL" wrote:

> yes i did-
>
>
> "Zekske" wrote in message
>
> > Did you enable the openrowset option in the Surface Area Configuration for
> > Features?
> >
> > "JTL" wrote:
> >
> >> i'm having the strangest problem right now and can't seem to figure out
> >> what's going on- here's the deal:
> >>
> >> i'm trying to use the openrowset command, in combination with the bulk
> >> insert command to load data from a text file into sql server. the text
> >> file
> >> im using has a field that can have a length when i execute the
> >> following, i
> >> receive a "Bulk load data conversion error (truncation) ":
> >>
> >> INSERT INTO tTempImport
> >> SELECT *
> >> FROM OPENROWSET(
> >> BULK 'E:\temp\myimportfile.txt',
> >> FORMATFILE = 'E:\temp\myformatfile.fmt'
> >> ) as t1
> >>
> >>
> >> however, this works just fine:
> >>
> >> BULK INSERT tTempImport
> >> FROM 'E:\temp\myimportfile.txt'
> >> WITH (FORMATFILE = 'E:\temp\myformatfile.fmt')
> >>
> >>
> >> ** the field in the import file that is causing the error has a length of
> >> 13988 characters
> >> ** the "Bulk load data conversion error (truncation) " error has nothing
> >> to
> >> do with the insert, as i get the same thing when just running the select
> >> *
> >> from openrowset... portion
> >>
> >> *** so what is it about the select * from openrowset command, that is
> >> causing sql server to do some sort of conversion on the data in the text
> >> file???
> >>
> >> --========================================================
> >> here are the contents of my format file:
> >> --========================================================
> >> 9.0
> >> 8
> >> 1 SQLCHAR 0 0 "\"" 0 "" ""
> >> 2 SQLCHAR 0 0 "|" 2 col2
> >> SQL_Latin1_General_CP1_CI_AS
> >> 3 SQLCHAR 0 0 "|" 3 col3
> >> SQL_Latin1_General_CP1_CI_AS
> >> 4 SQLCHAR 0 0 "|" 4 col4
> >> SQL_Latin1_General_CP1_CI_AS
> >> 5 SQLCHAR 0 0 "|" 5 col5
> >> SQL_Latin1_General_CP1_CI_AS
> >> 6 SQLCHAR 0 0 "|" 6 col6
> >> SQL_Latin1_General_CP1_CI_AS
> >> 7 SQLCHAR 0 0 "|" 7 col7
> >> SQL_Latin1_General_CP1_CI_AS
> >> 8 SQLCHAR 0 0 "|\"\r\n" 8 col8
> >> SQL_Latin1_General_CP1_CI_AS
> >>
> >>
> >> --========================================================
> >> --here is the table definition for tTempImport:
> >> --========================================================
> >> CREATE TABLE [dbo].[tTempImport](
> >> [id] [int] IDENTITY(1,1) NOT NULL,
> >> [col2] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> >> [col3] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> >> [col4] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> >> [col5] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> >> [col6] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> >> [col7] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> >> [col8] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> >> CONSTRAINT [PK_tTempImport] PRIMARY KEY CLUSTERED
> >> (
> >> [id] ASC
> >> )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
> >> ) ON [PRIMARY]
> >>
> >>
> >> TIA!!!
> >> jt
> >>
> >>
> >>
> >>
> >>
>
>
>
 >> Stay informed about: bulk insert and openrowset 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 5) Posted: Sun Jan 14, 2007 12:05 am
Post subject: Re: bulk insert and openrowset [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

JTL (jt@clickstreamtech.com) writes:
> i'm having the strangest problem right now and can't seem to figure out
> what's going on- here's the deal:
>
> i'm trying to use the openrowset command, in combination with the bulk
> insert command to load data from a text file into sql server. the text
> file im using has a field that can have a length when i execute the
> following, i receive a "Bulk load data conversion error (truncation) ":
>
> INSERT INTO tTempImport
> SELECT *
> FROM OPENROWSET(
> BULK 'E:\temp\myimportfile.txt',
> FORMATFILE = 'E:\temp\myformatfile.fmt'
> ) as t1
>
>
> however, this works just fine:
>
> BULK INSERT tTempImport
> FROM 'E:\temp\myimportfile.txt'
> WITH (FORMATFILE = 'E:\temp\myformatfile.fmt')
>
>
> ** the field in the import file that is causing the error has a length of
> 13988 characters
> ** the "Bulk load data conversion error (truncation) " error has nothing
> to do with the insert, as i get the same thing when just running the
> select * from openrowset... portion

I was able to repeat this so far that I got the error when I ran SELECT
FROM OPENROWSET without the INSERT. However, when I ran the compete
INSERT statement, the rows were inserted successfully.
--
Erland Sommarskog, SQL Server MVP, esquel.TakeThisOut@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 >> Stay informed about: bulk insert and openrowset 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Bulk Insert vs OpenRowset w/ Text Driver - Very frequently, roughly every 10 seconds, I need to load data from a staging file. The data will not load directly into the destination table(s), but needs intermediary processing. The amount of data with each load will be smallish (dozens to maybe a....

BULK insert - I am trying to do bulk insert 5000 rows into a simple table that has: id pk identity, col_text nvarchar(500) How do i do bulk insert but to only insert data that is not duplicated eg. if i have already in table 'some_text' and bulk inserting ..

Bulk insert problem - Hi! I have done bcp out using -V and -q switch from one table and using only -V switch on another table on the server running on sql server 2000. the datatype used is native i.e. -n switch. When I am trying to import it using BCP IN in the server..

Permissions and Bulk Insert - SS2005. I have a need for users to BULK INSERT files on an adhoc basis. Basically they want to upload a file and have immediate access. Right now, I'm doing that by assigning those users to the bulkadmin server role, and having them call a procedure..

Bulk Insert into New Table - I'm trying to Bulk Insert data but the table has yet to be created. I don't know what the definition of the table should be so the data imports without a hitch. Any suggestions?
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]