显示标签为“insert”的博文。显示所有博文
显示标签为“insert”的博文。显示所有博文

2012年3月29日星期四

bcp_exec() Failed

Has anyone had the above error ?

We ahve an app that uses a C++ to bulk insert into a database, and
during the procedure it some times gives us a error "bcp_exec()
Failed"

Any ideas.

Cheers.john (johnboy1973@.hotmail.com) writes:
> Has anyone had the above error ?

Many times!

> We ahve an app that uses a C++ to bulk insert into a database, and
> during the procedure it some times gives us a error "bcp_exec()
> Failed"

But I cannot recall that the error comes alone, but is always preceded
by other error messages which tells you what the problems with the
bulk copy is. The message "bcp_exec() failed" can be about anything.

If you have more error messagee, please share them too. If you don't,
maybe you should review the error handling in your C++ program, so that
it is not swallowing all error messagee but the last one.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Cheers. The c++ app is not handling the error at all well, but
compains occasionally in the event logs of invalid xml.

Cheers|||john (johnboy1973@.hotmail.com) writes:
> Cheers. The c++ app is not handling the error at all well, but
> compains occasionally in the event logs of invalid xml.

Looks like you need to improve the error handling then.

Which client library are you using? Coming from the DB-Library corner,
I assumed that you were using that. But there might be a bcp_exec() in
other libraries too. And DB-Library does not understand XML. Then again
I can't see where XML comes into the picture with any bulk-load operation.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Its a pain, basically, the app is VB6 connects to com services which
are written in C++, accessed via iis6 .asp page. So it gets the data
it requires from a sql database via a com+ / C++ Dll. Then trys to
pass the result set through bcp.

So im assuming its not the bcp that is at fault but the app pasing the
data too it. So off we go again in a circle.

Thanks for youre input though.

John|||john (johnboy1973@.hotmail.com) writes:
> Its a pain, basically, the app is VB6 connects to com services which
> are written in C++, accessed via iis6 .asp page. So it gets the data
> it requires from a sql database via a com+ / C++ Dll. Then trys to
> pass the result set through bcp.
> So im assuming its not the bcp that is at fault but the app pasing the
> data too it. So off we go again in a circle.

Maybe. But permit me to make the comment that a major reason that I am
not able to give better advice is that I know precious little of your
application. From wnat you describe above, it seems quite complex, and
maybe it's too complex to cover in a newsgroup posting.

But the general rule is: the more precise information you provide, the
more likely it will be that you get a useful answer.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

bcp: starting copy...

hello - i have this problem:
i am able to use bulk insert script like
"bulk insert demodb..table1
from 'c:\filename.ext' with (formatfile = 'c:\bcp.fmt')"
to import a binary file into sql server.
table1 has 4 columns, noted column is number 2, type image, here's my format file:
8.0
1
1 SQLIMAGE 0 100184 "" 2 logo ""
i import only the binary file.
however when trying to do the same using bcp with the same format file, it just says
"starting copy..." and goes to sleep !
any idea what i should do?
i created a temp table with just an IMAGE column and then the bcp method works, but i rather need it with my current setup - table with 4 columns

thank youAny error or information on SQL error log for this behaviour.

Can take help of PROFILER to see the activity during this execution.

BCP/Bulk Insert Datetime Problem,

Hi,

I am having problems getting BCP/Bulk Insert to insert dates properly.

The dates are being presented to us as,

dd/MM/yyyy hh:mm:ss

however, when importing into SQL Server as a datetime field via bcp/bulk insert, they are being inserted as

MM/dd/yyyy hh:mm:ss

In Australia, Windows region date setting set correctly and using Latin1_General_CI_AS collation.

Using the following format file (just the relevant sample from the file),

8.0
9
1 SQLCHAR 0 17 "," 1 startDateTime Latin1_General_CI_AS

I tried using

1 SQLDATETIME 0 17 "," 1 startDateTime ""

however this did not work.

Please let me know if any additional info needed.

Thanks!Dates are stored internally as numbers...the rest is just a presentation issue...look up convert in BOLsql

BCP/Bulk Insert and Incoming Dates

Ladies and Gentlemen
Is their a way to force BCP to accept a Date Value of
'000000'
instead of giving an error?
I am using BULK INSERT with a FORMAT FILE.
Mark MossHi Mark
The easiest way would be to use a staging table and then you can cater for
this when you update the main table. Another alternative would be to use DTS
an AnctiveX transform or possibly a lookup.
John
"Mark Moss" wrote:

> Ladies and Gentlemen
>
> Is their a way to force BCP to accept a Date Value of
> '000000'
> instead of giving an error?
>
> I am using BULK INSERT with a FORMAT FILE.
>
> Mark Moss
>
>

bcp/BULK INSERT and blank lines

Does anyone know of a way to make BULK INSERT or bcp ignore blank lines in the file? I am having trouble with a bunch of data files coming back with 1 or 2 blank lines at the end, and it causes the entire bcp to fail.

I suppose I could write a utility to trim the files but that seems a bit overkill. Any thoughts?

You will need to trim the data 'cuz bcp/bulk insert is just a _dumb_ data loader.|||One option is to use the -L parameter of BCP to specify the last row. This will let you ignore the lines at the end that is not formatted correctly. However, you have to count the lines in the file and subtract the offending number of lines to specify the value. If this doesn't work for you then you will have to correct the data file before using it with BCP or BULK INSERT.|||ah, -L! Thanks for the correction. I've never used that flag. It seems much simpler to just trim the blank lines...

BCP/BULK INSERT

Hi everyone,
I have to load data from a .txt file into a database table, I've decided to
use the BULK INSERT command because of the speed it has. At the first phase,
all data from the text file inserted to a temporaly table, which has only
varchar(x) fields, the second phase will process the data.
I have problems with the first phase, some records of the text file are not
well-formed, some fields are missing in several rows (this by design,
unfortunatly).
If the last field is missing, it will be null, as I excepted it.
But, if the the last two (or more) fields are missing, the it seems the
whole line shifted, and BCP starts to read the next row. And, of course, it
produces an error ("String or binary data would be truncated"). If I turn off
the ANSI_WARNINGS, I'll have a lot of false data - because of the "shift".
I'm using format files, all the fields are SQLCHAR by default, all of them
has a correct field length.
You could reproduce the error of course, with the following test script:
if exists(select 1 from sysobjects where name='table1')
begin
drop table table1;
end;
create table table1(
field1 varchar(2),
field2 varchar(2),
field3 varchar(2)
);
go
truncate table table1;
bulk insert table1 from 'table1.txt' with (formatfile='table1.fmt');
select * from table1;
go
The format file:
8.0
3
1 SQLCHAR 0 2 "" 1 field1
Hungarian_CI_AS
2 SQLCHAR 0 2 "" 2 field2
Hungarian_CI_AS
3 SQLCHAR 0 2 "\r\n" 3 field3
Hungarian_CI_AS
The data file:
01AAaa
02BBbb
03CCcc
04DD
05EE
06
07
08HH
09IIii
Has anyone a help or suggestion to resolve this problem? I do not want to
hardcode this process .
Thanks,
Tamas Beri
Hi
Modify it for your needs
1)
select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt;
*.csv)};
DefaultDir=D:\myfolder;','select * from data1.txt')
--Text file structure
col1
01AAaa
02BBbb
03CCcc
04DD
05EE
06
07
08HH
09IIii
2)
CREATE TABLE [tt] (
[ModuleID] [int] IDENTITY (1, 1) NOT NULL ,
[field1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[field2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL
) ON [PRIMARY]
GO
BULK INSERT tt
FROM 'd:\dat1.txt'
WITH
(
FIRSTROW = 3,
FORMATFILE = 'd:\fmt1.fmt'
)
select * from tt
--Text file structure
field1,field2
01,AAaa
02,BBbb
03,CCcc
04,DD
05,EE
06,
07,
08,HH
09,IIii
--fmt file structure
8.0
2
1 SQLCHAR 0 100 "," 2 field1
SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 10 "\r\n" 3 field2
SQL_Latin1_General_CP1_CI_AS
"gfoyle" <gfoyle@.discussions.microsoft.com> wrote in message
news:2E818698-6ABB-4820-BB41-57BA89477D11@.microsoft.com...
> Hi everyone,
> I have to load data from a .txt file into a database table, I've decided
to
> use the BULK INSERT command because of the speed it has. At the first
phase,
> all data from the text file inserted to a temporaly table, which has only
> varchar(x) fields, the second phase will process the data.
> I have problems with the first phase, some records of the text file are
not
> well-formed, some fields are missing in several rows (this by design,
> unfortunatly).
> If the last field is missing, it will be null, as I excepted it.
> But, if the the last two (or more) fields are missing, the it seems the
> whole line shifted, and BCP starts to read the next row. And, of course,
it
> produces an error ("String or binary data would be truncated"). If I turn
off
> the ANSI_WARNINGS, I'll have a lot of false data - because of the "shift".
> I'm using format files, all the fields are SQLCHAR by default, all of
them
> has a correct field length.
> You could reproduce the error of course, with the following test script:
> if exists(select 1 from sysobjects where name='table1')
> begin
> drop table table1;
> end;
> create table table1(
> field1 varchar(2),
> field2 varchar(2),
> field3 varchar(2)
> );
> go
> truncate table table1;
> bulk insert table1 from 'table1.txt' with (formatfile='table1.fmt');
> select * from table1;
> go
> The format file:
> 8.0
> 3
> 1 SQLCHAR 0 2 "" 1
field1
> Hungarian_CI_AS
> 2 SQLCHAR 0 2 "" 2
field2
> Hungarian_CI_AS
> 3 SQLCHAR 0 2 "\r\n" 3
field3
> Hungarian_CI_AS
> The data file:
> 01AAaa
> 02BBbb
> 03CCcc
> 04DD
> 05EE
> 06
> 07
> 08HH
> 09IIii
> Has anyone a help or suggestion to resolve this problem? I do not want to
> hardcode this process .
> Thanks,
> Tamas Beri
>
|||Thanks,
finally I've decided to read the data in two steps, at first in a temp
table which has only one row, and then the second phase is an insert into
select from with a massive using of substring, cast and case .
Another strange thing, I've tried to create a procedure:
create procedure some_procedure(@.filename varchar(256)) as
begin
bulk insert some_table from @.filename with(codepage='raw');
end;
go
And the creation fails, it says, "Incorrect syntax near '@.filename'.".
?
It is possible to pass the bulk insert command a variable?
Regards,
Tamas Beri
"Uri Dimant" wrote:

> Hi
> Modify it for your needs
> 1)
> select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt;
> *.csv)};
> DefaultDir=D:\myfolder;','select * from data1.txt')
> --Text file structure
> col1
> 01AAaa
> 02BBbb
> 03CCcc
> 04DD
> 05EE
> 06
> 07
> 08HH
> 09IIii
> 2)
> CREATE TABLE [tt] (
> [ModuleID] [int] IDENTITY (1, 1) NOT NULL ,
> [field1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [field2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
> NULL
> ) ON [PRIMARY]
> GO
>
> BULK INSERT tt
> FROM 'd:\dat1.txt'
> WITH
> (
> FIRSTROW = 3,
> FORMATFILE = 'd:\fmt1.fmt'
> )
> select * from tt
> --Text file structure
> field1,field2
> 01,AAaa
> 02,BBbb
> 03,CCcc
> 04,DD
> 05,EE
> 06,
> 07,
> 08,HH
> 09,IIii
> --fmt file structure
> 8.0
> 2
> 1 SQLCHAR 0 100 "," 2 field1
> SQL_Latin1_General_CP1_CI_AS
> 2 SQLCHAR 0 10 "\r\n" 3 field2
> SQL_Latin1_General_CP1_CI_AS

BCP/BULK INSERT

Hi everyone,
I have to load data from a .txt file into a database table, I've decided to
use the BULK INSERT command because of the speed it has. At the first phase,
all data from the text file inserted to a temporaly table, which has only
varchar(x) fields, the second phase will process the data.
I have problems with the first phase, some records of the text file are not
well-formed, some fields are missing in several rows (this by design,
unfortunatly).
If the last field is missing, it will be null, as I excepted it.
But, if the the last two (or more) fields are missing, the it seems the
whole line shifted, and BCP starts to read the next row. And, of course, it
produces an error ("String or binary data would be truncated"). If I turn off
the ANSI_WARNINGS, I'll have a lot of false data - because of the "shift".
I'm using format files, all the fields are SQLCHAR by default, all of them
has a correct field length.
You could reproduce the error of course, with the following test script:
if exists(select 1 from sysobjects where name='table1')
begin
drop table table1;
end;
create table table1(
field1 varchar(2),
field2 varchar(2),
field3 varchar(2)
);
go
truncate table table1;
bulk insert table1 from 'table1.txt' with (formatfile='table1.fmt');
select * from table1;
go
The format file:
8.0
3
1 SQLCHAR 0 2 "" 1 field1
Hungarian_CI_AS
2 SQLCHAR 0 2 "" 2 field2
Hungarian_CI_AS
3 SQLCHAR 0 2 "\r\n" 3 field3
Hungarian_CI_AS
The data file:
01AAaa
02BBbb
03CCcc
04DD
05EE
06
07
08HH
09IIii
Has anyone a help or suggestion to resolve this problem? I do not want to
hardcode this process :).
Thanks,
Tamas BeriHi
Modify it for your needs
1)
select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt;
*.csv)};
DefaultDir=D:\myfolder;','select * from data1.txt')
--Text file structure
col1
01AAaa
02BBbb
03CCcc
04DD
05EE
06
07
08HH
09IIii
2)
CREATE TABLE [tt] (
[ModuleID] [int] IDENTITY (1, 1) NOT NULL ,
[field1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[field2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL
) ON [PRIMARY]
GO
BULK INSERT tt
FROM 'd:\dat1.txt'
WITH
(
FIRSTROW = 3,
FORMATFILE = 'd:\fmt1.fmt'
)
select * from tt
--Text file structure
field1,field2
01,AAaa
02,BBbb
03,CCcc
04,DD
05,EE
06,
07,
08,HH
09,IIii
--fmt file structure
8.0
2
1 SQLCHAR 0 100 "," 2 field1
SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 10 "\r\n" 3 field2
SQL_Latin1_General_CP1_CI_AS
"gfoyle" <gfoyle@.discussions.microsoft.com> wrote in message
news:2E818698-6ABB-4820-BB41-57BA89477D11@.microsoft.com...
> Hi everyone,
> I have to load data from a .txt file into a database table, I've decided
to
> use the BULK INSERT command because of the speed it has. At the first
phase,
> all data from the text file inserted to a temporaly table, which has only
> varchar(x) fields, the second phase will process the data.
> I have problems with the first phase, some records of the text file are
not
> well-formed, some fields are missing in several rows (this by design,
> unfortunatly).
> If the last field is missing, it will be null, as I excepted it.
> But, if the the last two (or more) fields are missing, the it seems the
> whole line shifted, and BCP starts to read the next row. And, of course,
it
> produces an error ("String or binary data would be truncated"). If I turn
off
> the ANSI_WARNINGS, I'll have a lot of false data - because of the "shift".
> I'm using format files, all the fields are SQLCHAR by default, all of
them
> has a correct field length.
> You could reproduce the error of course, with the following test script:
> if exists(select 1 from sysobjects where name='table1')
> begin
> drop table table1;
> end;
> create table table1(
> field1 varchar(2),
> field2 varchar(2),
> field3 varchar(2)
> );
> go
> truncate table table1;
> bulk insert table1 from 'table1.txt' with (formatfile='table1.fmt');
> select * from table1;
> go
> The format file:
> 8.0
> 3
> 1 SQLCHAR 0 2 "" 1
field1
> Hungarian_CI_AS
> 2 SQLCHAR 0 2 "" 2
field2
> Hungarian_CI_AS
> 3 SQLCHAR 0 2 "\r\n" 3
field3
> Hungarian_CI_AS
> The data file:
> 01AAaa
> 02BBbb
> 03CCcc
> 04DD
> 05EE
> 06
> 07
> 08HH
> 09IIii
> Has anyone a help or suggestion to resolve this problem? I do not want to
> hardcode this process :).
> Thanks,
> Tamas Beri
>|||Thanks,
finally I've decided to read the data in two steps, at first in a temp
table which has only one row, and then the second phase is an insert into
select from with a massive using of substring, cast and case :).
Another strange thing, I've tried to create a procedure:
create procedure some_procedure(@.filename varchar(256)) as
begin
bulk insert some_table from @.filename with(codepage='raw');
end;
go
And the creation fails, it says, "Incorrect syntax near '@.filename'.".
?
It is possible to pass the bulk insert command a variable?
Regards,
Tamas Beri
"Uri Dimant" wrote:
> Hi
> Modify it for your needs
> 1)
> select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt;
> *.csv)};
> DefaultDir=D:\myfolder;','select * from data1.txt')
> --Text file structure
> col1
> 01AAaa
> 02BBbb
> 03CCcc
> 04DD
> 05EE
> 06
> 07
> 08HH
> 09IIii
> 2)
> CREATE TABLE [tt] (
> [ModuleID] [int] IDENTITY (1, 1) NOT NULL ,
> [field1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [field2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
> NULL
> ) ON [PRIMARY]
> GO
>
> BULK INSERT tt
> FROM 'd:\dat1.txt'
> WITH
> (
> FIRSTROW = 3,
> FORMATFILE = 'd:\fmt1.fmt'
> )
> select * from tt
> --Text file structure
> field1,field2
> 01,AAaa
> 02,BBbb
> 03,CCcc
> 04,DD
> 05,EE
> 06,
> 07,
> 08,HH
> 09,IIii
> --fmt file structure
> 8.0
> 2
> 1 SQLCHAR 0 100 "," 2 field1
> SQL_Latin1_General_CP1_CI_AS
> 2 SQLCHAR 0 10 "\r\n" 3 field2
> SQL_Latin1_General_CP1_CI_AS

BCP/BULK INSERT

Hi everyone,
I have to load data from a .txt file into a database table, I've decided to
use the BULK INSERT command because of the speed it has. At the first phase,
all data from the text file inserted to a temporaly table, which has only
varchar(x) fields, the second phase will process the data.
I have problems with the first phase, some records of the text file are not
well-formed, some fields are missing in several rows (this by design,
unfortunatly).
If the last field is missing, it will be null, as I excepted it.
But, if the the last two (or more) fields are missing, the it seems the
whole line shifted, and BCP starts to read the next row. And, of course, it
produces an error ("String or binary data would be truncated"). If I turn of
f
the ANSI_WARNINGS, I'll have a lot of false data - because of the "shift".
I'm using format files, all the fields are SQLCHAR by default, all of them
has a correct field length.
You could reproduce the error of course, with the following test script:
if exists(select 1 from sysobjects where name='table1')
begin
drop table table1;
end;
create table table1(
field1 varchar(2),
field2 varchar(2),
field3 varchar(2)
);
go
truncate table table1;
bulk insert table1 from 'table1.txt' with (formatfile='table1.fmt');
select * from table1;
go
The format file:
8.0
3
1 SQLCHAR 0 2 "" 1 field1
Hungarian_CI_AS
2 SQLCHAR 0 2 "" 2 field2
Hungarian_CI_AS
3 SQLCHAR 0 2 "\r\n" 3 field3
Hungarian_CI_AS
The data file:
01AAaa
02BBbb
03CCcc
04DD
05EE
06
07
08HH
09IIii
Has anyone a help or suggestion to resolve this problem? I do not want to
hardcode this process .
Thanks,
Tamas BeriHi
Modify it for your needs
1)
select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.t
xt;
*.csv)};
DefaultDir=D:\myfolder;','select * from data1.txt')
--Text file structure
col1
01AAaa
02BBbb
03CCcc
04DD
05EE
06
07
08HH
09IIii
2)
CREATE TABLE [tt] (
[ModuleID] [int] IDENTITY (1, 1) NOT NULL ,
[field1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NU
LL
,
[field2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL
) ON [PRIMARY]
GO
BULK INSERT tt
FROM 'd:\dat1.txt'
WITH
(
FIRSTROW = 3,
FORMATFILE = 'd:\fmt1.fmt'
)
select * from tt
--Text file structure
field1,field2
01,AAaa
02,BBbb
03,CCcc
04,DD
05,EE
06,
07,
08,HH
09,IIii
--fmt file structure
8.0
2
1 SQLCHAR 0 100 "," 2 field1
SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 10 "\r\n" 3 field2
SQL_Latin1_General_CP1_CI_AS
"gfoyle" <gfoyle@.discussions.microsoft.com> wrote in message
news:2E818698-6ABB-4820-BB41-57BA89477D11@.microsoft.com...
> Hi everyone,
> I have to load data from a .txt file into a database table, I've decided
to
> use the BULK INSERT command because of the speed it has. At the first
phase,
> all data from the text file inserted to a temporaly table, which has only
> varchar(x) fields, the second phase will process the data.
> I have problems with the first phase, some records of the text file are
not
> well-formed, some fields are missing in several rows (this by design,
> unfortunatly).
> If the last field is missing, it will be null, as I excepted it.
> But, if the the last two (or more) fields are missing, the it seems the
> whole line shifted, and BCP starts to read the next row. And, of course,
it
> produces an error ("String or binary data would be truncated"). If I turn
off
> the ANSI_WARNINGS, I'll have a lot of false data - because of the "shift".
> I'm using format files, all the fields are SQLCHAR by default, all of
them
> has a correct field length.
> You could reproduce the error of course, with the following test script:
> if exists(select 1 from sysobjects where name='table1')
> begin
> drop table table1;
> end;
> create table table1(
> field1 varchar(2),
> field2 varchar(2),
> field3 varchar(2)
> );
> go
> truncate table table1;
> bulk insert table1 from 'table1.txt' with (formatfile='table1.fmt');
> select * from table1;
> go
> The format file:
> 8.0
> 3
> 1 SQLCHAR 0 2 "" 1
field1
> Hungarian_CI_AS
> 2 SQLCHAR 0 2 "" 2
field2
> Hungarian_CI_AS
> 3 SQLCHAR 0 2 "\r\n" 3
field3
> Hungarian_CI_AS
> The data file:
> 01AAaa
> 02BBbb
> 03CCcc
> 04DD
> 05EE
> 06
> 07
> 08HH
> 09IIii
> Has anyone a help or suggestion to resolve this problem? I do not want to
> hardcode this process .
> Thanks,
> Tamas Beri
>|||Thanks,
finally I've decided to read the data in two steps, at first in a temp
table which has only one row, and then the second phase is an insert into
select from with a massive using of substring, cast and case .
Another strange thing, I've tried to create a procedure:
create procedure some_procedure(@.filename varchar(256)) as
begin
bulk insert some_table from @.filename with(codepage='raw');
end;
go
And the creation fails, it says, "Incorrect syntax near '@.filename'.".
?
It is possible to pass the bulk insert command a variable?
Regards,
Tamas Beri
"Uri Dimant" wrote:

> Hi
> Modify it for your needs
> 1)
> select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver
(*.txt;
> *.csv)};
> DefaultDir=D:\myfolder;','select * from data1.txt')
> --Text file structure
> col1
> 01AAaa
> 02BBbb
> 03CCcc
> 04DD
> 05EE
> 06
> 07
> 08HH
> 09IIii
> 2)
> CREATE TABLE [tt] (
> [ModuleID] [int] IDENTITY (1, 1) NOT NULL ,
> [field1] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL
> ,
> [field2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
> NULL
> ) ON [PRIMARY]
> GO
>
> BULK INSERT tt
> FROM 'd:\dat1.txt'
> WITH
> (
> FIRSTROW = 3,
> FORMATFILE = 'd:\fmt1.fmt'
> )
> select * from tt
> --Text file structure
> field1,field2
> 01,AAaa
> 02,BBbb
> 03,CCcc
> 04,DD
> 05,EE
> 06,
> 07,
> 08,HH
> 09,IIii
> --fmt file structure
> 8.0
> 2
> 1 SQLCHAR 0 100 "," 2 field1
> SQL_Latin1_General_CP1_CI_AS
> 2 SQLCHAR 0 10 "\r\n" 3 field2
> SQL_Latin1_General_CP1_CI_ASsql

2012年3月27日星期二

BCP will delete '\' chars on insert of character data

I've discovered that when using BCP to insert character data, then for any s
equence '\' + <newline> (backslash + ASCII 13), the '\' character is strippe
d. For example, try inserting this:
"Hello\\n"
and you'll wind up with
"Hello\n"
Can I turn this behavior off, or is this a known bug in BCP?
I'm using BCP with the SQL Server 7 ODBC driver.
Thanks,
Jim FloodJim Flood wrote:

> I've discovered that when using BCP to insert character data, then for any
sequence '' + <newline> (backslash + ASCII 13), the '' character is strip
ped. For example, try inserting this:
> "Hello\\n"
> and you'll wind up with
> "Hello\n"
> Can I turn this behavior off, or is this a known bug in BCP?
> I'm using BCP with the SQL Server 7 ODBC driver.
> Thanks,
> Jim Flood|||Can you verify the version number of the ODBC driver? You can do this be
running the ODBC Administrator and looking for the Version for the "SQL
Server" driver on the Drivers tab. Or, you can check the version of
sqlsrv32.dll in your system32 directory using Explorer.
We tried this with an 8.0 ODBC Driver and it does not repro. Before I go
setup a machine with SQL 7.0 on it, I want to verify your version number, to
make sure I get the same version.
Brannon Jones
Developer - MDAC
This posting is provided "as is" with no warranties and confers no rights.
"Jim Flood" <anonymous@.discussions.microsoft.com> wrote in message
news:DA87D286-F669-4F74-A5E5-82A9CBDEE5BE@.microsoft.com...
> I've discovered that when using BCP to insert character data, then for any
sequence '' + <newline> (backslash + ASCII 13), the '' character is
stripped. For example, try inserting this:
> "Hello\\n"
> and you'll wind up with
> "Hello\n"
> Can I turn this behavior off, or is this a known bug in BCP?
> I'm using BCP with the SQL Server 7 ODBC driver.
> Thanks,
> Jim Flood|||The version number is 2000.81.9042.0. The sequence is backslash character, f
ollowed by newline character. Backslash followed by any other character does
not cause a problem.

Bcp utility with stored procedure

Guys,

I have stored proc sp_generate_insert which will generate insert scripts for the tables. When I run the stored Proc
from the management studio it runs fine. But when I run through stored proc as part of BCP utility I get this error.

'SQLState = 42000, NativeError = 536
Error = [Microsoft][SQL Native Client][SQL Server]Invalid length parameter passed to the SUBSTRING function.'

Execute dev.dbo.sp_generate_inserts 'auth' runs fine from management studio and generates inserts for auth table.

When I run the same proc as part of the following stored proc with bcp utility I get the error.

alter PROCEDURE INSERTTEST2 ( @.FILEPATH NVARCHAR(50))
AS
DECLARE @.cmd varchar(2000)
BEGIN
set @.cmd = 'bcp.exe "EXEC dev.dbo.SP_GENERATE_INSERTS auth" '
+ 'QUERYOUT' + ' ' +@.filePath+ '.sql ' +'-S ' +
'NV-DEVSQL3' + ' -q ' + ' -c -T -e' + @.filePath+'.log -o '
+ @.filePath+ '_out.log'
select @.cmd -- + '...'
EXEC master.dbo.xp_cmdShell @.cmd
END

Any suggestions or inputs would help.

Thanks

The problem lies within the proc, so we need to see that code.

Though usually, this error comes from statements where the length parameter in SUBSTRING becomes negative.

If you're dynamically trying to set how large chunk substring should take, and that variable becomes negative, then this error happens.

Since the problem seems to occur or not depending on method of connecting, it may suggest that there are different settings that may be the root cause.. (ie ANSI DEFAULTS etc)

Could this be it perhaps?

/Kenneth

|||kenneth,

Thank you for you reply.

I dont know if the problem is setting defaults on the database or the connection, more so since the stored proc - sp_generate_scripts runs fine from the managment studio.

Anyways the code for stored proc is available at the following link

http://vyaskn.tripod.com/code/generate_inserts_2005.txt

Any suggestions/inputs would help

Thanks

|||

I played around a bit with the proc and found some 'interesting' stuff...

I think your problem may be that you don't use the -d parameter in your bcp command, so you're not ending up in the right db.

The reason this matters may be the same that I found, but didn't notice at first...

(I tried it on SQL Server 2000).
First when compiled, there was a msg about not finding sys.sp_MS_marksystemobject, but the proc compiled anyway, so I tried it out.

Got the same message as you a couple of times, but found that only if I was in a db other than master. Made a usertable in master, then it worked. =Surprise/

So, fixed the 'sys.sp_MS_marksystemobject' to 'sp_MS_marksystemobject' and recompiled (since the former doesn't exist in 2000, only in 2005) and tried again. Now all is smooth, and it works like it's supposed to.

Apparently, the proc needs to be marked as a systemobject, else you may get these 'db-scope' issues, so check out if this is the problem.

/Kenneth

2012年3月25日星期日

Bcp to insert the records from .dbf file into a sql database table

Hi

i need to inser the .dbf file records into sql table.

How should i go about it?

regards,

Kiran

Care to expand on what a .dbf file is and what it looks like inside?

/Kenneth

|||Hi Kiran, Have you used BCP before? Is your question concerning how to use BCP or do you need instructions on using the FoxPro and Visual FoxPro OLE DB data provider to set up your BCP? What have you tried to do so far? What troubles have you had? -- Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP cindy_winegarden@.msn.com www.cindywinegarden.com wrote in message news:8e96aa4b-3e3f-4bdb-a8b3-ae949f3a059d@.discussions.microsoft.com...
> i need to inser the .dbf file records into sql table. >
> How should i go about it?|||Hi KeWin, DBF-extension tables can be created by several different apps, but in general they are FoxPro or Visual FoxPro tables. They are readable via the FoxPro and Visual FoxPro OLE DB data provider, and older tables are also readable via the FoxPro and Visual FoxPro ODBC drivers. -- Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP cindy_winegarden@.msn.com www.cindywinegarden.com wrote in message news:2db5480f-3d86-4f78-8f62-cac33c9222c9@.discussions.microsoft.com...
> Care to expand on what a .dbf file is and what it looks like inside? >
> /Kenneth >
>|||

Hi,

yes i have used bcp to export data in a csv file to a remote machine. But now i want to make a bulk insert of data from a dbf file to sql server 2000 database table.

This can be done through DTS but my question is that is it possible by bcp? if yes then how?

~Kiran

|||Hi Kiran, Rather than BCP you could set up a linked server and then use Insert Into ..... Select. -- Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP cindy_winegarden@.msn.com www.cindywinegarden.com wrote in message news:ccc1df84-24a5-4cc1-9b78-86e7674d6ccb@.discussions.microsoft.com...
> Hi, >
> yes i have used bcp to export data in a csv file to a remote machine.
> But now i want to make a bulk insert of data from a dbf file to sql
> server 2000 database table. >
> This can be done through DTS but my question is that is it possible by
> bcp? if yes then how? >
> ~Kiran > > >
>

2012年3月22日星期四

BCP process

I have a question about BCP in
When i do a BCP in from a file which has 3 mill records, the BCP insert goes
in very fast with notification showing 1000 records at a time but when all
rows are inserted after 3 mill records it takes considerable time for BCP in
to get over.
What is it doing at each stage '
Ps- Table has a primary key so i assume its a slow BCP
SanjaySanjay,
It's doing one big honking transaction.
Use the -b switch to set a batch size upon import.
That way it will commit each batch separately.
Just remember, if it blows off, it's up to you to clean up the mess.
Example:
BCP myserver.dbo.mytable IN
d:\mssql\transfer\MyBCPFile.txt -Smyserver -Umyuser -Pmypassword -n -b1000
James Hokes
"Sanjay" <sanjayg@.hotmail.com> wrote in message
news:589E306B-667F-49DF-BE90-4CDCB5713662@.microsoft.com...
quote:

> I have a question about BCP in
> When i do a BCP in from a file which has 3 mill records, the BCP insert

goes in very fast with notification showing 1000 records at a time but when
all rows are inserted after 3 mill records it takes considerable time for
BCP in to get over.
quote:

> What is it doing at each stage '
> Ps- Table has a primary key so i assume its a slow BCP
> Sanjay
>
|||You mean its doin a COMMIT right...
But why is it taking that long i thought a commit is just like including a m
arker
Checkpoint is actuallly the process which writes committed transaction to th
e disk so that should be the one taking time.
Also which one is better in speed using -b1000 or doing it in one big transa
ction
Sanjay|||Hi Sanjay,
Yes. Each batch will be treated as a separate transaction.
Since you have 3 Million records to load, You can go for -b10000 (Commit
will be made after loading 10000 records),. This will speed up your process
considerably.
Thanks
Hari
MCDBA
"Sanjay" <sanjayg@.hotmail.com> wrote in message
news:0D546BCA-DBBB-4B19-BF1E-5A604D9F15D2@.microsoft.com...
quote:

> You mean its doin a COMMIT right...
> But why is it taking that long i thought a commit is just like including a

marker
quote:

> Checkpoint is actuallly the process which writes committed transaction to

the disk so that should be the one taking time.
quote:

> Also which one is better in speed using -b1000 or doing it in one big

transaction
quote:

> Sanjay
>
|||examnotes (sanjayg@.hotmail.com) writes:
quote:

> I have a question about BCP in
> When i do a BCP in from a file which has 3 mill records, the BCP insert
> goes in very fast with notification showing 1000 records at a time but
> when all rows are inserted after 3 mill records it takes considerable
> time for BCP in to get over.
> What is it doing at each stage '

I've seen this too. I have not investigated what it actually does.
Maybe it's rebuilding the index, maybe it is just committing the
data.
Even if using -b10000 will avoid this delay at the end, it does not
mean that this is faster. You will have to benchmark to find out.
My gut feeling is that as long as your log can stand it, having all
in one transaction is the best.
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

BCP process

I have a question about BCP i
When i do a BCP in from a file which has 3 mill records, the BCP insert goes in very fast with notification showing 1000 records at a time but when all rows are inserted after 3 mill records it takes considerable time for BCP in to get over
What is it doing at each stage ?
Ps- Table has a primary key so i assume its a slow BC
SanjaSanjay,
It's doing one big honking transaction.
Use the -b switch to set a batch size upon import.
That way it will commit each batch separately.
Just remember, if it blows off, it's up to you to clean up the mess.
Example:
BCP myserver.dbo.mytable IN
d:\mssql\transfer\MyBCPFile.txt -Smyserver -Umyuser -Pmypassword -n -b1000
James Hokes
"Sanjay" <sanjayg@.hotmail.com> wrote in message
news:589E306B-667F-49DF-BE90-4CDCB5713662@.microsoft.com...
> I have a question about BCP in
> When i do a BCP in from a file which has 3 mill records, the BCP insert
goes in very fast with notification showing 1000 records at a time but when
all rows are inserted after 3 mill records it takes considerable time for
BCP in to get over.
> What is it doing at each stage '
> Ps- Table has a primary key so i assume its a slow BCP
> Sanjay
>|||Hi Sanjay,
Yes. Each batch will be treated as a separate transaction.
Since you have 3 Million records to load, You can go for -b10000 (Commit
will be made after loading 10000 records),. This will speed up your process
considerably.
Thanks
Hari
MCDBA
"Sanjay" <sanjayg@.hotmail.com> wrote in message
news:0D546BCA-DBBB-4B19-BF1E-5A604D9F15D2@.microsoft.com...
> You mean its doin a COMMIT right...
> But why is it taking that long i thought a commit is just like including a
marker
> Checkpoint is actuallly the process which writes committed transaction to
the disk so that should be the one taking time.
> Also which one is better in speed using -b1000 or doing it in one big
transaction
> Sanjay
>|||=?Utf-8?B?U2FuamF5?= (sanjayg@.hotmail.com) writes:
> I have a question about BCP in
> When i do a BCP in from a file which has 3 mill records, the BCP insert
> goes in very fast with notification showing 1000 records at a time but
> when all rows are inserted after 3 mill records it takes considerable
> time for BCP in to get over.
> What is it doing at each stage '
I've seen this too. I have not investigated what it actually does.
Maybe it's rebuilding the index, maybe it is just committing the
data.
Even if using -b10000 will avoid this delay at the end, it does not
mean that this is faster. You will have to benchmark to find out.
My gut feeling is that as long as your log can stand it, having all
in one transaction is the best.
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

2012年3月19日星期一

BCP Order on SQL Server

I have two SQL Server 2000 machines. The same file is sent nightly to
each server and a stored proc uses BULK INSERT to load it into a
staging table for processing.

Once I've bcp'ed it in, I put it into a temp table with an IDENTITY
column appended to it. (I need this identity column to group by later
on to remove duplicates.)

ie

select tempo.*,
IDENTITY(int, 1,1) AS ID_Num
into #test1
from tempExtract tempo

My question is : can I expect the ID_Num and the corresponding line of
the file copied to the table to be the same on each server? Ie will
each BCP into the staging table occur in the same order on both
servers given that the file, the BULK INSERT command and the indexes
are the same on each server.Thomas Richards (tom.richards@.rocketmail.com) writes:
> I have two SQL Server 2000 machines. The same file is sent nightly to
> each server and a stored proc uses BULK INSERT to load it into a
> staging table for processing.
> Once I've bcp'ed it in, I put it into a temp table with an IDENTITY
> column appended to it. (I need this identity column to group by later
> on to remove duplicates.)
> ie
> select tempo.*,
> IDENTITY(int, 1,1) AS ID_Num
> into #test1
> from tempExtract tempo
> My question is : can I expect the ID_Num and the corresponding line of
> the file copied to the table to be the same on each server? Ie will
> each BCP into the staging table occur in the same order on both
> servers given that the file, the BULK INSERT command and the indexes
> are the same on each server.

No, you would need to have the identity column on the table you load
the file into. I don't know for sure that you can trust the IDENTITY
value to match the input file exactly, and if it works, it is likely
to by mere chance. That is, there is no committment from Microsoft
that it should work, and it could change in a future version of SQL
Server.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland Sommarskog <esquel@.sommarskog.se> wrote in message news:<Xns9556E943F45FAYazorman@.127.0.0.1>...
> Thomas Richards (tom.richards@.rocketmail.com) writes:
> > I have two SQL Server 2000 machines. The same file is sent nightly to
> > each server and a stored proc uses BULK INSERT to load it into a
> > staging table for processing.
> > Once I've bcp'ed it in, I put it into a temp table with an IDENTITY
> > column appended to it. (I need this identity column to group by later
> > on to remove duplicates.)
> > ie
> > select tempo.*,
> > IDENTITY(int, 1,1) AS ID_Num
> > into #test1
> > from tempExtract tempo
> > My question is : can I expect the ID_Num and the corresponding line of
> > the file copied to the table to be the same on each server? Ie will
> > each BCP into the staging table occur in the same order on both
> > servers given that the file, the BULK INSERT command and the indexes
> > are the same on each server.
> No, you would need to have the identity column on the table you load
> the file into. I don't know for sure that you can trust the IDENTITY
> value to match the input file exactly, and if it works, it is likely
> to by mere chance. That is, there is no committment from Microsoft
> that it should work, and it could change in a future version of SQL
> Server.

Thanks for that. The problem that I'm trying to get round is that I
have a key field and then one or more addresses. The key field and the
fields that make up the address are all chars/varchars. I want to pick
one arbitrary address to associate with the key and put in another
table. There are no business rules (eg always take the one with the
lowest street number) that will always identify just one of the
addresses. Originally, I thought group by key and line number and pick
the one with the lowest number. I would prefer to do this as it would
get the first entry in the file which would more than likely give me
the better address details. However as you've pointed out I can't
depend on the order when bcp'ed in. Is there any other way to do this
or would I have to get line number added to the file before SQL Server
processes it?|||Thomas Richards (tom.richards@.rocketmail.com) writes:
> Thanks for that. The problem that I'm trying to get round is that I
> have a key field and then one or more addresses. The key field and the
> fields that make up the address are all chars/varchars. I want to pick
> one arbitrary address to associate with the key and put in another
> table. There are no business rules (eg always take the one with the
> lowest street number) that will always identify just one of the
> addresses. Originally, I thought group by key and line number and pick
> the one with the lowest number. I would prefer to do this as it would
> get the first entry in the file which would more than likely give me
> the better address details. However as you've pointed out I can't
> depend on the order when bcp'ed in. Is there any other way to do this
> or would I have to get line number added to the file before SQL Server
> processes it?

The only way to be sure is to add the line numbers yourself. This can be
done in two ways: 1) Manipulate the file, by running it through a program
that adds a line number. 2) Instead of writing a to file, have the program
to insert the data. In fact, you can still use bulk load, but you would
bulk from variables, using the BCP API.

However, BULK INSERT into a table with an IDENTITY gives you fairly good
odds, and as I understand your case, it does not seem to be a disaster,
if number is not what you expect. So I would go for that.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks,

I'm going to have problems adding the line numbers to the file unless
there's an easy way to do it that uses windows built-in functionality.
Unfortunately the file comes from a mainframe extract so the I can't
change the program either.

Just to be clear about what I'm doing, I bulk insert into a table that
has a KEY field and then one or more addresses eg:

KEY, ADDRESS1, ADDRESS2
----------
FRED, HOG STREET, HOGLAND
FRED, HOG STREET, HOGLANDIO

I need to take the key (ie FRED) and one address (doesn't matter
which) and put it into another table. However, I have to get the same
address on each server. That's more important than trying to get the
first one in the file.

I'm going to try out the bulk insert with identity. If I put a
clustered key on the table that is bulk inserted to on all columns, I
would assume that would force the order in the table to be the same on
both servers - what do you think?

Cheers
Tom

> The only way to be sure is to add the line numbers yourself. This can be
> done in two ways: 1) Manipulate the file, by running it through a program
> that adds a line number. 2) Instead of writing a to file, have the program
> to insert the data. In fact, you can still use bulk load, but you would
> bulk from variables, using the BCP API.
> However, BULK INSERT into a table with an IDENTITY gives you fairly good
> odds, and as I understand your case, it does not seem to be a disaster,
> if number is not what you expect. So I would go for that.|||My latest thinking on this is to create a table the same as the table
holding the 'key' and address components but with an extra identity
type field.

Then insert into this table ordering by key + all columns. This will
force the sequence number to match the same row on each server and the
'key' fields to be sequentially next to each other. Then I can do a
group by, picking up the lowest sequence number.

eg

SELECT KEY,
ADDRESS1,
ADDRESS2,
IDENTITY(int,1,1) as Seq
INTO tempTable
FROM tempExtract
WHERE 1=2

INSERT INTO tempTable
SELECT KEY,
ADDRESS1,
ADDRESS2
FROM tempExtract
ORDER BY KEY,
ADDRESS1,
ADDRESS2

-- Finally get a key with just one address
SELECT KEY,
ADDRESS1,
ADDRESS2
FROM tempTable
WHERE SEQ = (SELECT MIN (Seq)
FROM tempTable sub
WHERE sub.KEY = tempTable.KEY)

Can you see any holes in that?!

Cheers
Tom|||Thomas Richards (tom.richards@.rocketmail.com) writes:
> I'm going to have problems adding the line numbers to the file unless
> there's an easy way to do it that uses windows built-in functionality.

Adding such line numbers is a very simple program that can be written
VBscript, Perl, C or whatever your preference is. The one catch is that
this is not very effcient if the file is huge.

> I'm going to try out the bulk insert with identity. If I put a
> clustered key on the table that is bulk inserted to on all columns, I
> would assume that would force the order in the table to be the same on
> both servers - what do you think?

What matters is the order that the rows hit the tables. My guess is that
a completely indexless table is better.

> INSERT INTO tempTable
> SELECT KEY,
> ADDRESS1,
> ADDRESS2
> FROM tempExtract
> ORDER BY KEY,
> ADDRESS1,
> ADDRESS2
>...
> Can you see any holes in that?!

The sad case is that neither is there any guarantee with an INSERT
statement that the IDENITTY value will reflect the ORDER BY statement.
But if you add OPTION (MAXDOP 1) to the query it usually works. MAXDOP 1
turns off parallelism which is the major reason the ORDER BY gets messed up.

But maybe you should rethink completely. Maybe you should bulk into one
server, remove the duplicates, and the replicate the result to the
second server. This could be done by a linked query, or bulking out and
in again.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||My latest thinking on this is to create a table the same as the table
holding the 'key' and address components but with an extra identity
type field.

Then insert into this table ordering by key + all columns. This will
force the sequence number to match the same row on each server and the
'key' fields to be sequentially next to each other. Then I can do a
group by, picking up the lowest sequence number.

eg

SELECT KEY,
ADDRESS1,
ADDRESS2,
IDENTITY(int,1,1) as Seq
INTO tempTable
FROM tempExtract
WHERE 1=2

INSERT INTO tempTable
SELECT KEY,
ADDRESS1,
ADDRESS2
FROM tempExtract
ORDER BY KEY,
ADDRESS1,
ADDRESS2

-- Finally get a key with just one address
SELECT KEY,
ADDRESS1,
ADDRESS2
FROM tempTable
WHERE SEQ = (SELECT MIN (Seq)
FROM tempTable sub
WHERE sub.KEY = tempTable.KEY)

Can you see any holes in that?!

Cheers
Tom|||Thomas Richards (tom.richards@.rocketmail.com) writes:
> My latest thinking on this is to create a table the same as the table
> holding the 'key' and address components but with an extra identity
> type field.
> Then insert into this table ordering by key + all columns. This will
> force the sequence number to match the same row on each server and the
> 'key' fields to be sequentially next to each other. Then I can do a
> group by, picking up the lowest sequence number.
>...

That seems to the same suggestion, to which I answered once, so I
simply repear that answer:

The sad case is that neither is there any guarantee with an INSERT
statement that the IDENITTY value will reflect the ORDER BY statement.
But if you add OPTION (MAXDOP 1) to the query it usually works. MAXDOP 1
turns off parallelism which is the major reason the ORDER BY gets messed up.

But maybe you should rethink completely. Maybe you should bulk into one
server, remove the duplicates, and the replicate the result to the
second server. This could be done by a linked query, or bulking out and
in again.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Sorry, what I meant to post was:

I'm thinking of doing the following to ensure I get the same row on
each server (assuming identical collations).
It is supposed to only bring back the row that matches the TOP value
of all the fields concatenated. I've tested it on identical servers
and it appears to work and the theory seems fine to me. Can you see
anything wrong with this??

Thanks
Tom

SELECT KEY,
ADDRESS1,
ADDRESS2
FROM TABLE main
WHERE ISNULL(KEY,'Z') +
ISNULL(ADDRESS1, 'Z') +
ISNULL(ADDRESS2, 'Z') =
(SELECT TOP 1 ISNULL(KEY, 'Z') +
ISNULL(ADDRESS1, 'Z') +
ISNULL(ADDRESS2, 'Z') =
FROM TABLE sub
WHERE sub.KEY = main.KEY
ORDER BY ISNULL(KEY,'Z') +
ISNULL(ADDRESS1, 'Z') +
ISNULL(ADDRESS2, 'Z'))|||Thomas Richards (tom.richards@.rocketmail.com) writes:
> I'm thinking of doing the following to ensure I get the same row on
> each server (assuming identical collations).
> It is supposed to only bring back the row that matches the TOP value
> of all the fields concatenated. I've tested it on identical servers
> and it appears to work and the theory seems fine to me. Can you see
> anything wrong with this??
> Thanks
> Tom
> SELECT KEY,
> ADDRESS1,
> ADDRESS2
> FROM TABLE main
> WHERE ISNULL(KEY,'Z') +
> ISNULL(ADDRESS1, 'Z') +
> ISNULL(ADDRESS2, 'Z') =
> (SELECT TOP 1 ISNULL(KEY, 'Z') +
> ISNULL(ADDRESS1, 'Z') +
> ISNULL(ADDRESS2, 'Z') =
> FROM TABLE sub
> WHERE sub.KEY = main.KEY
> ORDER BY ISNULL(KEY,'Z') +
> ISNULL(ADDRESS1, 'Z') +
> ISNULL(ADDRESS2, 'Z'))

You could get duplicates if you have some really weird data which
gives the same result for two concatenations, but I guess that is
a calculated risk. And you would get the same duplicates on both
servers.

Ah, there is one more catch - you must make sure that both databases
have the same collation. But since you can specify the collation per
column when you create the table, you can take care of that.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

BCP or BULK INSERT, which one is better to use.

Hi,
I have some data in ANSI txt file, i want to know which one would be
better and recommended way to import this into table. bcp or BULK
INSERT
Appreciate your inputs on this.
Thanks,
ManojPersonally, I use bcp , only because of the added flexibility that I can
also output into a data file
Jack Vamvas
________________________________________
__________________________
Receive free SQL tips - register at www.ciquery.com/sqlserver.htm
SQL Server Performance Audit - check www.ciquery.com/sqlserver_audit.htm
New article by Jack Vamvas - SQL and Markov Chains -
www.ciquery.com/articles/art_04.asp
"Manoj" <manoj_poonia@.dell.com> wrote in message
news:1139581478.079428.98540@.g47g2000cwa.googlegroups.com...
> Hi,
> I have some data in ANSI txt file, i want to know which one would be
> better and recommended way to import this into table. bcp or BULK
> INSERT
> Appreciate your inputs on this.
> Thanks,
> Manoj
>|||Manoj (manoj_poonia@.dell.com) writes:
> I have some data in ANSI txt file, i want to know which one would be
> better and recommended way to import this into table. bcp or BULK
> INSERT
I seem to recall that I saw some numbers that indicated that BULK
INSERT is considerably faster than BCP.
However, with moderate volumes simplicity may be more important.
BULK INSERT requires that the file is visible from SQL Server. That
is, on the same machine as SQL Server, or a network drive that
SQL Server can see. For BCP there is no such requirement.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

BCP into image columns

I'm trying to use the bcp executable to insert rows into a table
containing two guids and two image columns. I'm using an explicit
character string for the field delimiter, and another for the row
delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
command I get an error.
C:\>bcp tempdb..t_test in test.bcp -t "||^t^||" -r "||^r^||" -S
myserver -U uname -P pwd -c -N
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Unexpected EOF encountered
in BCP data-file
0 rows copied.
I tried the same bcp command with a format file provided, and still
received that same errror. The format file is as follows.
8.0
4
1 SQLUNIQUEID 1 16 "||^t^||" 1
guid1 ""
2 SQLUNIQUEID 1 16 "||^t^||" 2
guid2 ""
3 SQLIMAGE 4 0 "||^t^||" 3
img1 ""
4 SQLIMAGE 4 0 "||^r^||" 4
img2 ""
Am I missing something here? Or are image columns just a pain to work
with?
--ian(ian_jacobsen@.hotmail.com) writes:
> I'm trying to use the bcp executable to insert rows into a table
> containing two guids and two image columns. I'm using an explicit
> character string for the field delimiter, and another for the row
> delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
> command I get an error.
And how does the data in the file look like? Judging from your description
there is newlines in it. Is that correct?

> I tried the same bcp command with a format file provided, and still
> received that same errror. The format file is as follows.
> 8.0
> 4
> 1 SQLUNIQUEID 1 16 "||^t^||" 1 guid1 ""
> 2 SQLUNIQUEID 1 16 "||^t^||" 2 guid2 ""
> 3 SQLIMAGE 4 0 "||^t^||" 3 img1 ""
> 4 SQLIMAGE 4 0 "||^r^||" 4 img2 ""
That's a format file for a binary file. Your BCP command was for a
character file.

> Am I missing something here? Or are image columns just a pain to work
> with?
image are indeed difficult to deal with, but I have a feeling you have
not reached those problems yet. :-) SQL 2005 has varbinary(MAX) which
can fit as much data as image, but is a lot easier to deal with.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||>From your reply I'm guessing that my approach is wrong. The data that
I am trying to insert into the image column is an xml file that has
been compressed. Since it is very costly to store xml in its native
state, I would like to compress this data and store it in the database.
I'm exporting a dataset to xml, compressing that data, and then I
append this data onto my bcp file containing the two guids. In fact I
have two datasets that I'm trying to append. Is there a better way to
go about compression? Or a better way to format my bcp file?

>And how does the data in the file look like?
I'd rather not post the contents of my bcp file here (since its filled
with binary data and would be a mess), but here is a sample of the
layout with the binary cut down.
035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-5a0bbfcb=
a033||^t^||PK
Ti4||^t^||PK Ti4||^r^||

>Judging from your description there is newlines in it. Is that correct?
I'm presuming that a binary file can contain any characters, including
newlines.
--ian|||(ian_jacobsen@.hotmail.com) writes:
> From your reply I'm guessing that my approach is wrong. The data that
> I am trying to insert into the image column is an xml file that has
> been compressed. Since it is very costly to store xml in its native
> state, I would like to compress this data and store it in the database.
Undoubtedly, SQL 2005 should be very appealing to you, as it has a
built-in xml data type.

> I'd rather not post the contents of my bcp file here (since its filled
> with binary data and would be a mess), but here is a sample of the
> layout with the binary cut down.
Ah, that clarifies things quite a bit. This format file could work:
8.0
4
1 SQLCHAR 0 0 "||^t^||" 1 guid1 ""
2 SQLCHAR 0 0 "||^t^||" 2 guid2 ""
3 SQLIMAGE 0 0 "||^t^||" 3 img1 ""
4 SQLIMAGE 0 0 "||^r^||" 4 img2 ""
Since the GUIDs appears as text in the data file, the correct data
type for these is SQLCHAR. I've also set the prefix length to 0,
as your file does not seem to include length prefixes. (Although this
could be a better choice for the image columns, rather than using
a separator which in case of bad luck could appear in the data.

> 035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-
5a0bbfcba033||^t^||PK
> Ti4||^t^||PK Ti4||^r^||
And the next GUID appears directly after ||, that is no newline?
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||When using the format file that you provided, this fixed the problem I
was having.
Thanks
--IAN|||(ian_jacobsen@.hotmail.com) writes:
> When using the format file that you provided, this fixed the problem I
> was having.
Ah! I am glad to hear that! I was afraid that it would not be that simple,
but we would hit some other snag.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

BCP into image columns

I'm trying to use the bcp executable to insert rows into a table
containing two guids and two image columns. I'm using an explicit
character string for the field delimiter, and another for the row
delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
command I get an error.
C:\>bcp tempdb..t_test in test.bcp -t "||^t^||" -r "||^r^||" -S
myserver -U uname -P pwd -c -N
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Unexpected EOF encountered
in BCP data-file
0 rows copied.
I tried the same bcp command with a format file provided, and still
received that same errror. The format file is as follows.
8.0
4
1 SQLUNIQUEID 1 16 "||^t^||" 1
guid1 ""
2 SQLUNIQUEID 1 16 "||^t^||" 2
guid2 ""
3 SQLIMAGE 4 0 "||^t^||" 3
img1 ""
4 SQLIMAGE 4 0 "||^r^||" 4
img2 ""
Am I missing something here? Or are image columns just a pain to work
with?
--ian
(ian_jacobsen@.hotmail.com) writes:
> I'm trying to use the bcp executable to insert rows into a table
> containing two guids and two image columns. I'm using an explicit
> character string for the field delimiter, and another for the row
> delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
> command I get an error.
And how does the data in the file look like? Judging from your description
there is newlines in it. Is that correct?

> I tried the same bcp command with a format file provided, and still
> received that same errror. The format file is as follows.
> 8.0
> 4
> 1 SQLUNIQUEID 1 16 "||^t^||" 1 guid1 ""
> 2 SQLUNIQUEID 1 16 "||^t^||" 2 guid2 ""
> 3 SQLIMAGE 4 0 "||^t^||" 3 img1 ""
> 4 SQLIMAGE 4 0 "||^r^||" 4 img2 ""
That's a format file for a binary file. Your BCP command was for a
character file.

> Am I missing something here? Or are image columns just a pain to work
> with?
image are indeed difficult to deal with, but I have a feeling you have
not reached those problems yet. :-) SQL 2005 has varbinary(MAX) which
can fit as much data as image, but is a lot easier to deal with.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
|||>From your reply I'm guessing that my approach is wrong. The data that
I am trying to insert into the image column is an xml file that has
been compressed. Since it is very costly to store xml in its native
state, I would like to compress this data and store it in the database.
I'm exporting a dataset to xml, compressing that data, and then I
append this data onto my bcp file containing the two guids. In fact I
have two datasets that I'm trying to append. Is there a better way to
go about compression? Or a better way to format my bcp file?

>And how does the data in the file look like?
I'd rather not post the contents of my bcp file here (since its filled
with binary data and would be a mess), but here is a sample of the
layout with the binary cut down.
035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-5a0bbfcb=
a033||^t^||PK
Ti4||^t^||PK Ti4||^r^||

>Judging from your description there is newlines in it. Is that correct?
I'm presuming that a binary file can contain any characters, including
newlines.
--ian
|||(ian_jacobsen@.hotmail.com) writes:
> From your reply I'm guessing that my approach is wrong. The data that
> I am trying to insert into the image column is an xml file that has
> been compressed. Since it is very costly to store xml in its native
> state, I would like to compress this data and store it in the database.
Undoubtedly, SQL 2005 should be very appealing to you, as it has a
built-in xml data type.

> I'd rather not post the contents of my bcp file here (since its filled
> with binary data and would be a mess), but here is a sample of the
> layout with the binary cut down.
Ah, that clarifies things quite a bit. This format file could work:
8.0
4
1 SQLCHAR 0 0 "||^t^||" 1 guid1 ""
2 SQLCHAR 0 0 "||^t^||" 2 guid2 ""
3 SQLIMAGE 0 0 "||^t^||" 3 img1 ""
4 SQLIMAGE 0 0 "||^r^||" 4 img2 ""
Since the GUIDs appears as text in the data file, the correct data
type for these is SQLCHAR. I've also set the prefix length to 0,
as your file does not seem to include length prefixes. (Although this
could be a better choice for the image columns, rather than using
a separator which in case of bad luck could appear in the data.

> 035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-
5a0bbfcba033||^t^||PK
> Ti4||^t^||PK Ti4||^r^||
And the next GUID appears directly after ||, that is no newline?
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
|||When using the format file that you provided, this fixed the problem I
was having.
Thanks
--IAN
|||(ian_jacobsen@.hotmail.com) writes:
> When using the format file that you provided, this fixed the problem I
> was having.
Ah! I am glad to hear that! I was afraid that it would not be that simple,
but we would hit some other snag.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx

BCP into image columns

I'm trying to use the bcp executable to insert rows into a table
containing two guids and two image columns. I'm using an explicit
character string for the field delimiter, and another for the row
delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
command I get an error.
C:\>bcp tempdb..t_test in test.bcp -t "||^t^||" -r "||^r^||" -S
myserver -U uname -P pwd -c -N
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Unexpected EOF encountered
in BCP data-file
0 rows copied.
I tried the same bcp command with a format file provided, and still
received that same errror. The format file is as follows.
8.0
4
1 SQLUNIQUEID 1 16 "||^t^||" 1
guid1 ""
2 SQLUNIQUEID 1 16 "||^t^||" 2
guid2 ""
3 SQLIMAGE 4 0 "||^t^||" 3
img1 ""
4 SQLIMAGE 4 0 "||^r^||" 4
img2 ""
Am I missing something here? Or are image columns just a pain to work
with?
--ian(ian_jacobsen@.hotmail.com) writes:
> I'm trying to use the bcp executable to insert rows into a table
> containing two guids and two image columns. I'm using an explicit
> character string for the field delimiter, and another for the row
> delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
> command I get an error.
And how does the data in the file look like? Judging from your description
there is newlines in it. Is that correct?
> I tried the same bcp command with a format file provided, and still
> received that same errror. The format file is as follows.
> 8.0
> 4
> 1 SQLUNIQUEID 1 16 "||^t^||" 1 guid1 ""
> 2 SQLUNIQUEID 1 16 "||^t^||" 2 guid2 ""
> 3 SQLIMAGE 4 0 "||^t^||" 3 img1 ""
> 4 SQLIMAGE 4 0 "||^r^||" 4 img2 ""
That's a format file for a binary file. Your BCP command was for a
character file.
> Am I missing something here? Or are image columns just a pain to work
> with?
image are indeed difficult to deal with, but I have a feeling you have
not reached those problems yet. :-) SQL 2005 has varbinary(MAX) which
can fit as much data as image, but is a lot easier to deal with.
Erland Sommarskog, SQL Server MVP, esquel@.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|||>From your reply I'm guessing that my approach is wrong. The data that
I am trying to insert into the image column is an xml file that has
been compressed. Since it is very costly to store xml in its native
state, I would like to compress this data and store it in the database.
I'm exporting a dataset to xml, compressing that data, and then I
append this data onto my bcp file containing the two guids. In fact I
have two datasets that I'm trying to append. Is there a better way to
go about compression? Or a better way to format my bcp file?
>And how does the data in the file look like?
I'd rather not post the contents of my bcp file here (since its filled
with binary data and would be a mess), but here is a sample of the
layout with the binary cut down.
035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-5a0bbfcb=a033||^t^||PK
Ti4||^t^||PK Ti4||^r^||
>Judging from your description there is newlines in it. Is that correct?
I'm presuming that a binary file can contain any characters, including
newlines.
--ian|||(ian_jacobsen@.hotmail.com) writes:
> From your reply I'm guessing that my approach is wrong. The data that
> I am trying to insert into the image column is an xml file that has
> been compressed. Since it is very costly to store xml in its native
> state, I would like to compress this data and store it in the database.
Undoubtedly, SQL 2005 should be very appealing to you, as it has a
built-in xml data type.
>>And how does the data in the file look like?
> I'd rather not post the contents of my bcp file here (since its filled
> with binary data and would be a mess), but here is a sample of the
> layout with the binary cut down.
Ah, that clarifies things quite a bit. This format file could work:
8.0
4
1 SQLCHAR 0 0 "||^t^||" 1 guid1 ""
2 SQLCHAR 0 0 "||^t^||" 2 guid2 ""
3 SQLIMAGE 0 0 "||^t^||" 3 img1 ""
4 SQLIMAGE 0 0 "||^r^||" 4 img2 ""
Since the GUIDs appears as text in the data file, the correct data
type for these is SQLCHAR. I've also set the prefix length to 0,
as your file does not seem to include length prefixes. (Although this
could be a better choice for the image columns, rather than using
a separator which in case of bad luck could appear in the data.
> 035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-
5a0bbfcba033||^t^||PK
> Ti4||^t^||PK Ti4||^r^||
And the next GUID appears directly after ||, that is no newline?
Erland Sommarskog, SQL Server MVP, esquel@.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|||When using the format file that you provided, this fixed the problem I
was having.
Thanks
--IAN|||(ian_jacobsen@.hotmail.com) writes:
> When using the format file that you provided, this fixed the problem I
> was having.
Ah! I am glad to hear that! I was afraid that it would not be that simple,
but we would hit some other snag.
Erland Sommarskog, SQL Server MVP, esquel@.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

BCP into image columns

I'm trying to use the bcp executable to insert rows into a table
containing two guids and two image columns. I'm using an explicit
character string for the field delimiter, and another for the row
delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
command I get an error.
C:\>bcp tempdb..t_test in test.bcp -t "||^t^||" -r "||^r^||" -S
myserver -U uname -P pwd -c -N
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Unexpected EOF encountere
d
in BCP data-file
0 rows copied.
I tried the same bcp command with a format file provided, and still
received that same errror. The format file is as follows.
8.0
4
1 SQLUNIQUEID 1 16 "||^t^||" 1
guid1 ""
2 SQLUNIQUEID 1 16 "||^t^||" 2
guid2 ""
3 SQLIMAGE 4 0 "||^t^||" 3
img1 ""
4 SQLIMAGE 4 0 "||^r^||" 4
img2 ""
Am I missing something here? Or are image columns just a pain to work
with?
--ian(ian_jacobsen@.hotmail.com) writes:
> I'm trying to use the bcp executable to insert rows into a table
> containing two guids and two image columns. I'm using an explicit
> character string for the field delimiter, and another for the row
> delimiter (not the usual "\t" and "\r\n"). When I do the following bcp
> command I get an error.
And how does the data in the file look like? Judging from your description
there is newlines in it. Is that correct?

> I tried the same bcp command with a format file provided, and still
> received that same errror. The format file is as follows.
> 8.0
> 4
> 1 SQLUNIQUEID 1 16 "||^t^||" 1 guid1 ""
> 2 SQLUNIQUEID 1 16 "||^t^||" 2 guid2 ""
> 3 SQLIMAGE 4 0 "||^t^||" 3 img1 ""
> 4 SQLIMAGE 4 0 "||^r^||" 4 img2 ""
That's a format file for a binary file. Your BCP command was for a
character file.

> Am I missing something here? Or are image columns just a pain to work
> with?
image are indeed difficult to deal with, but I have a feeling you have
not reached those problems yet. :-) SQL 2005 has varbinary(MAX) which
can fit as much data as image, but is a lot easier to deal with.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||>From your reply I'm guessing that my approach is wrong. The data that
I am trying to insert into the image column is an xml file that has
been compressed. Since it is very costly to store xml in its native
state, I would like to compress this data and store it in the database.
I'm exporting a dataset to xml, compressing that data, and then I
append this data onto my bcp file containing the two guids. In fact I
have two datasets that I'm trying to append. Is there a better way to
go about compression? Or a better way to format my bcp file?

>And how does the data in the file look like?
I'd rather not post the contents of my bcp file here (since its filled
with binary data and would be a mess), but here is a sample of the
layout with the binary cut down.
035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-5a0bbfcb=
a033||^t^||PK
Ti4||^t^||PK Ti4||^r^||

>Judging from your description there is newlines in it. Is that correct?
I'm presuming that a binary file can contain any characters, including
newlines.
--ian|||(ian_jacobsen@.hotmail.com) writes:
> From your reply I'm guessing that my approach is wrong. The data that
> I am trying to insert into the image column is an xml file that has
> been compressed. Since it is very costly to store xml in its native
> state, I would like to compress this data and store it in the database.
Undoubtedly, SQL 2005 should be very appealing to you, as it has a
built-in xml data type.

> I'd rather not post the contents of my bcp file here (since its filled
> with binary data and would be a mess), but here is a sample of the
> layout with the binary cut down.
Ah, that clarifies things quite a bit. This format file could work:
8.0
4
1 SQLCHAR 0 0 "||^t^||" 1 guid1 ""
2 SQLCHAR 0 0 "||^t^||" 2 guid2 ""
3 SQLIMAGE 0 0 "||^t^||" 3 img1 ""
4 SQLIMAGE 0 0 "||^r^||" 4 img2 ""
Since the GUIDs appears as text in the data file, the correct data
type for these is SQLCHAR. I've also set the prefix length to 0,
as your file does not seem to include length prefixes. (Although this
could be a better choice for the image columns, rather than using
a separator which in case of bad luck could appear in the data.

> 035caafb-db11-4c9a-8a60-acbcb434d5cf||^t^||177c5700-36b0-4a0b-b0b6-
5a0bbfcba033||^t^||PK
> Ti4||^t^||PK Ti4||^r^||
And the next GUID appears directly after ||, that is no newline?
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||When using the format file that you provided, this fixed the problem I
was having.
Thanks
--IAN|||(ian_jacobsen@.hotmail.com) writes:
> When using the format file that you provided, this fixed the problem I
> was having.
Ah! I am glad to hear that! I was afraid that it would not be that simple,
but we would hit some other snag.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

2012年3月11日星期日

BCP in using bcp_sendrow fails, not enough columns bound

Hello, first posting:
I am using bcp_sendrow to INSERT data from program variables into the
database.
I am sending less columns than the database contains, because new
columns need to be added to the tables before the program is changed.
However, despite the fact that the unspecified columns have default
values associated with them, I still get the error message:
"Not enough columns bound"
every time I attempt to insert a line. It does not matter if the
column is NULLable or not, I have determined that it will fail if the
unspecified columns are at the end of the table. Unspecified columns
in the middle of the table automatically get populated with the default
value or NULL.
Has anyone else come across this problem? Is there some sort of switch
I can use to make this work? The only solution I have come up with is
to insert new columns in the middle of the table, which I shouldn't
have to do (and it's slow at that).
Thanks in advance,
RobBind all columns and set the columns to ignore as NULL like this:
r = bcp_bind(hdbc, /* Database Handle */
(const LPCBYTE)"", /* Empty String */
0, /* 0 prefix len */
SQL_NULL_DATA, /* length of -1 = set column to NULL */
(const LPCBYTE)"", /* Terminator Char */
1, /* Terminator Length = 1 for \0x00 */
SQLCHARACTER, /* Column type */
Col_Num /* Column Number */
);
"Robert B" <rob@.automatedfinancial.com> wrote in message
news:1148604213.015728.148440@.38g2000cwa.googlegroups.com...
> Hello, first posting:
> I am using bcp_sendrow to INSERT data from program variables into the
> database.
> I am sending less columns than the database contains, because new
> columns need to be added to the tables before the program is changed.
> However, despite the fact that the unspecified columns have default
> values associated with them, I still get the error message:
> "Not enough columns bound"
> every time I attempt to insert a line. It does not matter if the
> column is NULLable or not, I have determined that it will fail if the
> unspecified columns are at the end of the table. Unspecified columns
> in the middle of the table automatically get populated with the default
> value or NULL.
> Has anyone else come across this problem? Is there some sort of switch
> I can use to make this work? The only solution I have come up with is
> to insert new columns in the middle of the table, which I shouldn't
> have to do (and it's slow at that).
>
> Thanks in advance,
> Rob
>|||Thanks, Mike,
I have no problem binding to a column and inserting NULL data. My
problem is that my program will fail with "not enough columns bound" as
soon as a new column is added to the table, even if the new column is
set to NULL, default NULL. I need to maintain some sort of
backwards-compatibility where the program will continue to work even
though I have not specified all the columns.
Rob|||I'm working on a similar problem myself right now. The fix I'm looking at
is to grab the column information from the table ahead of time and bind the
columns dynamically using that information. The info is available in the
INFORMATION_SCHEMA views, and I'm also testing a couple of other methods
myself. It's definitely more work, but definitely necessary in my case.
"Robert B" <rob@.automatedfinancial.com> wrote in message
news:1148659354.289141.188110@.j55g2000cwa.googlegroups.com...
> Thanks, Mike,
> I have no problem binding to a column and inserting NULL data. My
> problem is that my program will fail with "not enough columns bound" as
> soon as a new column is added to the table, even if the new column is
> set to NULL, default NULL. I need to maintain some sort of
> backwards-compatibility where the program will continue to work even
> though I have not specified all the columns.
> Rob
>