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

2012年3月29日星期四

bcp_bind and SQL DATETIME type

Hi all,
I'm working on a simple ODBC API bulk load application and I've run
into a problem. I am binding variables in memory and sending the rows
as prescribed in the ODBC 3.0 API Reference and on MSDN. Everything
works fine for SQL VARCHAR and SQL INTEGER data types; however, I run
into issues when I try to bind SQL DATETIME data types. I can't seem
to find examples of how this should be done anywhere... Should my
variable that I'm binding to be a C-Style string or a
SQL_TIMESTAMP_STRUCT or a time_t structure? It's all a blur...
Anyone know where I can find a sample that bcp_binds to a DATETIME
column in a table?
TIANever mind, issue resolved.
"Michael C#" wrote:

> Hi all,
> I'm working on a simple ODBC API bulk load application and I've run
> into a problem. I am binding variables in memory and sending the rows
> as prescribed in the ODBC 3.0 API Reference and on MSDN. Everything
> works fine for SQL VARCHAR and SQL INTEGER data types; however, I run
> into issues when I try to bind SQL DATETIME data types. I can't seem
> to find examples of how this should be done anywhere... Should my
> variable that I'm binding to be a C-Style string or a
> SQL_TIMESTAMP_STRUCT or a time_t structure? It's all a blur...
> Anyone know where I can find a sample that bcp_binds to a DATETIME
> column in a table?
> TIA
>|||Hello Michael,
Can you please show me an example that "works fine for SQL VARCHAR"? I just
can't send text using the bcp...
TIA
quote:
Originally posted by Michael C
Never mind, issue resolved.
"Michael C#" wrote:

> Hi all,
> I'm working on a simple ODBC API bulk load application and I've run
> into a problem. I am binding variables in memory and sending the rows
> as prescribed in the ODBC 3.0 API Reference and on MSDN. Everything
> works fine for SQL VARCHAR and SQL INTEGER data types; however, I run
> into issues when I try to bind SQL DATETIME data types. I can't seem
> to find examples of how this should be done anywhere... Should my
> variable that I'm binding to be a C-Style string or a
> SQL_TIMESTAMP_STRUCT or a time_t structure? It's all a blur...
> Anyone know where I can find a sample that bcp_binds to a DATETIME
> column in a table?
> TIA
>

|||Hi Michael, i am facing similar issue i.e. failing of bcp_binf for datetime
datatpye. Can You please share the solution that you have for this issue?
Thanks in advance.
From http://developmentnow.com/g/111_200...
ype.htm
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

2012年3月27日星期二

BCP with ODBC Native driver

We are using Visual Studio 2003 to develop a VC++ application to support SQL Server 2000 and 2005 through ODBC driver. I was able to successfully test the application with ODBC driver for 2000. But when it comes to the SQL Server 2005 using native ODBC driver it fails with "ODBCBCP.dll is not compatible with 'SQL Native Client' driver. Please configure 'SQL Server' driver for the DSN or connection string.

Then I tried to use the sqlncli.h inplace of odbcss.h and replaced the odbcbcp.lib with sqlncli.lib pointing to the C:\Program Files\Microsoft SQL Server\90\SDK\Lib\x86 folder.

Code Snippet

#include <sql.h>

#include <sqlext.h>

#include <sqltypes.h>

#define _SQLNCLI_ODBC_

#include <sqlncli.h>

Now I can not compile the program. The errors I am getting are as follows:

c:\Program Files\Microsoft SQL Server\90\SDK\Include\sqlncli.h(2894): error C2061: syntax error : identifier 'DB_UPARAMS'

c:\Program Files\Microsoft SQL Server\90\SDK\Include\sqlncli.h(2901): error C2061: syntax error : identifier 'DB_UPARAMS'
etc

c:\Program Files\Microsoft SQL Server\90\SDK\Include\sqlncli.h(2938): error C2061: syntax error : identifier 'HCHAPTER'
c:\Program Files\Microsoft SQL Server\90\SDK\Include\sqlncli.h(2944): error C2061: syntax error : identifier 'HCHAPTER'
etc

The same code just works fine in the Visual Studio 2005, but we need the dll in Visual studio 2003.

I think I am missing pretty obvious. Your help is appreciated.

Can you try not defining _SQLNCLI_ODBC_, I believe that would work.

Thanks

Waseem

sql

2012年3月25日星期日

BCP using ODBC - problem with unique identifier

Hi guys
I'm having a nasty problem with bulk copying into a table that has
unique identifier column. I'm coding on C++, using ODBC driver.
I'm coping from a file containing UID description like this:
{43B5B3DE-5280-4CBF-B357-D9E57651F0D1}
(I also tried a non-bracket version)
and in the DB table I get:
4233347B-4235-4433-452D-353238302D34
which seems random at first sight, but it is:
[B34{]-[B5]-[D3]-[E-]-[5280-4] - with chars read binary as hex.
and my question is: what the hell?
my code look like this:
if (bcp_init (m_hDbproc,tableName, NULL, NULL, DB_IN) == FAIL)
ret = -1;
if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, 16, (LPCBYTE)NULL, 0,
SQLUNIQUEID, colNo) == FAIL){
ret = -1;
}
(I also tried a VARLEN version:)
if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, SQL_VARLEN_DATA,
(LPCBYTE)delimiter, 1, SQLVARCHAR, colNo) == FAIL){
ret = -1;
}
and then stuff like sendrow ans save:
if (bcp_sendrow(m_hDbproc) == FAIL)
return -1;
if (bcp_batch (m_hDbproc) == -1)
return -1;
I also tried specyfiling the column type in the m_hDbproc handle as
SQLUNIQUEID, but either I'm doing something wrong, or this just isn't
the way of a bulk copy samurai:
INT * pValue=new INT;
INT *pLen=new INT;
*pValue=0x24;
bcp_setcolfmt(m_hDbproc,1,BCP_FMT_TYPE,pValue,4);
So like, PLEASE help me on this. I need to get this working by last
monday :]
Thanx, M.(mpietrzyk@.autograf.pl) writes:
> I'm having a nasty problem with bulk copying into a table that has
> unique identifier column. I'm coding on C++, using ODBC driver.
> I'm coping from a file containing UID description like this:
> {43B5B3DE-5280-4CBF-B357-D9E57651F0D1}
> (I also tried a non-bracket version)
> and in the DB table I get:
> 4233347B-4235-4433-452D-353238302D34
> which seems random at first sight, but it is:
> [B34{]-[B5]-[D3]-[E-]-[5280-4] - with chars read binary as hex.
> and my question is: what the hell?
> my code look like this:
> if (bcp_init (m_hDbproc,tableName, NULL, NULL, DB_IN) == FAIL)
> ret = -1;
> if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, 16, (LPCBYTE)NULL, 0,
> SQLUNIQUEID, colNo) == FAIL){
> ret = -1;
> }
> (I also tried a VARLEN version:)
> if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, SQL_VARLEN_DATA,
> (LPCBYTE)delimiter, 1, SQLVARCHAR, colNo) == FAIL){
> ret = -1;
> }
First you need to decide in which format is the UID? It if is in text,
you should specify SQLVARCHAR for the data type. Only if you have the
UID as binary, you should specify SQLUNIQUEID.
Even if you use SQLVARCHAR, I don't think SQL_VARLEN_DATA is correct.
It depends on what's in delimiter, but since a GUIO is always 36
characters (without braces), you could just as well specify 36 for the
length.
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|||> First you need to decide in which format is the UID? It if is in text,
> you should specify SQLVARCHAR for the data type. Only if you have the
> UID as binary, you should specify SQLUNIQUEID.
> Even if you use SQLVARCHAR, I don't think SQL_VARLEN_DATA is correct.
> It depends on what's in delimiter, but since a GUIO is always 36
> characters (without braces), you could just as well specify 36 for the
> length.
>
Thanx Erland,
I tried the approaches you mentioned:
1. Using SQLVARCHAR instead of SQLUNIQUEID results in "[Microsoft][ODBC
SQL Server Driver]Invalid character value for cast specification". What
do you meas format of the UID? You mean in the input file? in the input
file it is in "text format", like presented in my first post.
2. Setting length (for SQLUNIQUEID) different then 16 results in FAIL
result in bcp_bind.
Setting different then 16 for SQLVARCHAR still results in
"[Microsoft][ODBC SQL Server Driver]Invalid character value for cast
specification" error
Still no good.|||tha_mihau (mpietrzyk@.autograf.pl) writes:
> 1. Using SQLVARCHAR instead of SQLUNIQUEID results in "[Microsoft][ODBC
> SQL Server Driver]Invalid character value for cast specification". What
> do you meas format of the UID? You mean in the input file? in the input
> file it is in "text format", like presented in my first post.
The error message means that the string does not convert to a GUID.
This could be because you have not specified the appropriate length or
delimiter. I would try with 36 in length and no terminator.
> 2. Setting length (for SQLUNIQUEID) different then 16 results in FAIL
> result in bcp_bind.
Since you have text input, you should not use SQLUNIQUEID, unless you
convert the value in your program prior to passing it to BCP.
--
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 using ODBC - problem with unique identifier

Hi guys
I'm having a nasty problem with bulk copying into a table that has
unique identifier column. I'm coding on C++, using ODBC driver.
I'm coping from a file containing UID description like this:
{43B5B3DE-5280-4CBF-B357-D9E57651F0D1}
(I also tried a non-bracket version)
and in the DB table I get:
4233347B-4235-4433-452D-353238302D34
which seems random at first sight, but it is:
[B34{]-[B5]-[D3]-[E-]-[5280-4] - with chars read bi
nary as hex.
and my question is: what the hell?
my code look like this:
if (bcp_init (m_hDbproc,tableName, NULL, NULL, DB_IN) == FAIL)
ret = -1;
if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, 16, (LPCBYTE)NULL, 0,
SQLUNIQUEID, colNo) == FAIL){
ret = -1;
}
(I also tried a VARLEN version
if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, SQL_VARLEN_DATA,
(LPCBYTE)delimiter, 1, SQLVARCHAR, colNo) == FAIL){
ret = -1;
}
and then stuff like sendrow ans save:
if (bcp_sendrow(m_hDbproc) == FAIL)
return -1;
if (bcp_batch (m_hDbproc) == -1)
return -1;
I also tried specyfiling the column type in the m_hDbproc handle as
SQLUNIQUEID, but either I'm doing something wrong, or this just isn't
the way of a bulk copy samurai:
INT * pValue=new INT;
INT *pLen=new INT;
*pValue=0x24;
bcp_setcolfmt(m_hDbproc,1,BCP_FMT_TYPE,p
Value,4);
So like, PLEASE help me on this. I need to get this working by last
monday :]
Thanx, M.(mpietrzyk@.autograf.pl) writes:
> I'm having a nasty problem with bulk copying into a table that has
> unique identifier column. I'm coding on C++, using ODBC driver.
> I'm coping from a file containing UID description like this:
> {43B5B3DE-5280-4CBF-B357-D9E57651F0D1}
> (I also tried a non-bracket version)
> and in the DB table I get:
> 4233347B-4235-4433-452D-353238302D34
> which seems random at first sight, but it is:
> [B34{]-[B5]-[D3]-[E-]-[5280-4] - with chars read
binary as hex.
> and my question is: what the hell?
> my code look like this:
> if (bcp_init (m_hDbproc,tableName, NULL, NULL, DB_IN) == FAIL)
> ret = -1;
> if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, 16, (LPCBYTE)NULL, 0,
> SQLUNIQUEID, colNo) == FAIL){
> ret = -1;
> }
> (I also tried a VARLEN version
> if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, SQL_VARLEN_DATA,
> (LPCBYTE)delimiter, 1, SQLVARCHAR, colNo) == FAIL){
> ret = -1;
> }
First you need to decide in which format is the UID? It if is in text,
you should specify SQLVARCHAR for the data type. Only if you have the
UID as binary, you should specify SQLUNIQUEID.
Even if you use SQLVARCHAR, I don't think SQL_VARLEN_DATA is correct.
It depends on what's in delimiter, but since a GUIO is always 36
characters (without braces), you could just as well specify 36 for the
length.
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|||
> First you need to decide in which format is the UID? It if is in text,
> you should specify SQLVARCHAR for the data type. Only if you have the
> UID as binary, you should specify SQLUNIQUEID.
> Even if you use SQLVARCHAR, I don't think SQL_VARLEN_DATA is correct.
> It depends on what's in delimiter, but since a GUIO is always 36
> characters (without braces), you could just as well specify 36 for the
> length.
>
Thanx Erland,
I tried the approaches you mentioned:
1. Using SQLVARCHAR instead of SQLUNIQUEID results in "[Microsoft][O
DBC
SQL Server Driver]Invalid character value for cast specification". What
do you meas format of the UID? You mean in the input file? in the input
file it is in "text format", like presented in my first post.
2. Setting length (for SQLUNIQUEID) different then 16 results in FAIL
result in bcp_bind.
Setting different then 16 for SQLVARCHAR still results in
"[Microsoft][ODBC SQL Server Driver]Invalid character value for cast
specification" error
Still no good.|||tha_mihau (mpietrzyk@.autograf.pl) writes:
> 1. Using SQLVARCHAR instead of SQLUNIQUEID results in "[Microsoft][
;ODBC
> SQL Server Driver]Invalid character value for cast specification". What
> do you meas format of the UID? You mean in the input file? in the input
> file it is in "text format", like presented in my first post.
The error message means that the string does not convert to a GUID.
This could be because you have not specified the appropriate length or
delimiter. I would try with 36 in length and no terminator.

> 2. Setting length (for SQLUNIQUEID) different then 16 results in FAIL
> result in bcp_bind.
Since you have text input, you should not use SQLUNIQUEID, unless you
convert the value in your program prior to passing it to BCP.
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 using ODBC - problem with unique identifier

Hi guys

I'm having a nasty problem with bulk copying into a table that has
unique identifier column. I'm coding on C++, using ODBC driver.

I'm coping from a file containing UID description like this:
{43B5B3DE-5280-4CBF-B357-D9E57651F0D1}
(I also tried a non-bracket version)

and in the DB table I get:
4233347B-4235-4433-452D-353238302D34

which seems random at first sight, but it is:
[B34{]-[B5]-[D3]-[E-]-[5280-4] - with chars read binary as hex.

and my question is: what the hell?

my code look like this:

if (bcp_init (m_hDbproc,tableName, NULL, NULL, DB_IN) == FAIL)
ret = -1;

if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, 16, (LPCBYTE)NULL, 0,
SQLUNIQUEID, colNo) == FAIL){
ret = -1;
}

(I also tried a VARLEN version:)

if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, SQL_VARLEN_DATA,
(LPCBYTE)delimiter, 1, SQLVARCHAR, colNo) == FAIL){
ret = -1;
}

and then stuff like sendrow ans save:

if (bcp_sendrow(m_hDbproc) == FAIL)
return -1;
if (bcp_batch (m_hDbproc) == -1)
return -1;

I also tried specyfiling the column type in the m_hDbproc handle as
SQLUNIQUEID, but either I'm doing something wrong, or this just isn't
the way of a bulk copy samurai:

INT * pValue=new INT;
INT *pLen=new INT;
*pValue=0x24;
bcp_setcolfmt(m_hDbproc,1,BCP_FMT_TYPE,pValue,4);

So like, PLEASE help me on this. I need to get this working by last
monday :]

Thanx, M.(mpietrzyk@.autograf.pl) writes:

Quote:

Originally Posted by

I'm having a nasty problem with bulk copying into a table that has
unique identifier column. I'm coding on C++, using ODBC driver.
>
I'm coping from a file containing UID description like this:
{43B5B3DE-5280-4CBF-B357-D9E57651F0D1}
(I also tried a non-bracket version)
>
and in the DB table I get:
4233347B-4235-4433-452D-353238302D34
>
which seems random at first sight, but it is:
[B34{]-[B5]-[D3]-[E-]-[5280-4] - with chars read binary as hex.
>
and my question is: what the hell?
>
my code look like this:
>
if (bcp_init (m_hDbproc,tableName, NULL, NULL, DB_IN) == FAIL)
ret = -1;
>
if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, 16, (LPCBYTE)NULL, 0,
SQLUNIQUEID, colNo) == FAIL){
ret = -1;
}
>
(I also tried a VARLEN version:)
>
if (bcp_bind (m_hDbproc, (LPCBYTE)data, 0, SQL_VARLEN_DATA,
(LPCBYTE)delimiter, 1, SQLVARCHAR, colNo) == FAIL){
ret = -1;
}


First you need to decide in which format is the UID? It if is in text,
you should specify SQLVARCHAR for the data type. Only if you have the
UID as binary, you should specify SQLUNIQUEID.

Even if you use SQLVARCHAR, I don't think SQL_VARLEN_DATA is correct.
It depends on what's in delimiter, but since a GUIO is always 36
characters (without braces), you could just as well specify 36 for the
length.

--
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|||

Quote:

Originally Posted by

First you need to decide in which format is the UID? It if is in text,
you should specify SQLVARCHAR for the data type. Only if you have the
UID as binary, you should specify SQLUNIQUEID.
>
Even if you use SQLVARCHAR, I don't think SQL_VARLEN_DATA is correct.
It depends on what's in delimiter, but since a GUIO is always 36
characters (without braces), you could just as well specify 36 for the
length.
>
>


Thanx Erland,

I tried the approaches you mentioned:

1. Using SQLVARCHAR instead of SQLUNIQUEID results in "[Microsoft][ODBC
SQL Server Driver]Invalid character value for cast specification". What
do you meas format of the UID? You mean in the input file? in the input
file it is in "text format", like presented in my first post.
2. Setting length (for SQLUNIQUEID) different then 16 results in FAIL
result in bcp_bind.
Setting different then 16 for SQLVARCHAR still results in
"[Microsoft][ODBC SQL Server Driver]Invalid character value for cast
specification" error

Still no good.|||tha_mihau (mpietrzyk@.autograf.pl) writes:

Quote:

Originally Posted by

1. Using SQLVARCHAR instead of SQLUNIQUEID results in "[Microsoft][ODBC
SQL Server Driver]Invalid character value for cast specification". What
do you meas format of the UID? You mean in the input file? in the input
file it is in "text format", like presented in my first post.


The error message means that the string does not convert to a GUID.
This could be because you have not specified the appropriate length or
delimiter. I would try with 36 in length and no terminator.

Quote:

Originally Posted by

2. Setting length (for SQLUNIQUEID) different then 16 results in FAIL
result in bcp_bind.


Since you have text input, you should not use SQLUNIQUEID, unless you
convert the value in your program prior to passing it to BCP.

--
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|||Erland Sommarskog wrote:

Quote:

Originally Posted by

tha_mihau (mpietrzyk@.autograf.pl) writes:

Quote:

Originally Posted by

1. Using SQLVARCHAR instead of SQLUNIQUEID results in "[Microsoft][ODBC
SQL Server Driver]Invalid character value for cast specification". What
do you meas format of the UID? You mean in the input file? in the input
file it is in "text format", like presented in my first post.


>
The error message means that the string does not convert to a GUID.
This could be because you have not specified the appropriate length or
delimiter. I would try with 36 in length and no terminator.
>

Quote:

Originally Posted by

2. Setting length (for SQLUNIQUEID) different then 16 results in FAIL
result in bcp_bind.


>
Since you have text input, you should not use SQLUNIQUEID, unless you
convert the value in your program prior to passing it to BCP.


Thx, Erland!

Running
bcp_bind (m_hDbproc, (LPCBYTE)data, 0, 36, (LPCBYTE)NULL, 0,
SQLVARCHAR, colNo)
on a file with GUIDs with no braces did the trick.
Works like a charm.

Thanks again, M.sql

2012年3月20日星期二

BCP out from ODBC

Is it possible to BCP out from an ODBC data source?
It needs to be a SQL Server database to BCP out data.
-Sue
On Fri, 9 Apr 2004 11:37:54 -0700, "Drew"
<anonymous@.discussions.microsoft.com> wrote:

>Is it possible to BCP out from an ODBC data source?
>
|||While you can't BCP out from an ODBC data source you can use DTS to transfer
data out from an ODBC compliant data source.
"Drew" <anonymous@.discussions.microsoft.com> wrote in message
news:1a94901c41e61$c5532cc0$a301280a@.phx.gbl...
> Is it possible to BCP out from an ODBC data source?
>

BCP out from ODBC

Is it possible to BCP out from an ODBC data source?It needs to be a SQL Server database to BCP out data.
-Sue
On Fri, 9 Apr 2004 11:37:54 -0700, "Drew"
<anonymous@.discussions.microsoft.com> wrote:

>Is it possible to BCP out from an ODBC data source?
>|||While you can't BCP out from an ODBC data source you can use DTS to transfer
data out from an ODBC compliant data source.
"Drew" <anonymous@.discussions.microsoft.com> wrote in message
news:1a94901c41e61$c5532cc0$a301280a@.phx
.gbl...
> Is it possible to BCP out from an ODBC data source?
>

2012年2月23日星期四

bcp api and error handling

I have implemented a VB.NET application which uses the ODBC BCP api to bulk
insert data into a Microsoft SQL 2000 database. I have included error
handling as it is important to trap and log any errors when they occur. The
import works fine, and the error handling works fine for any ODBC errors
(server not found, login problems etc are all logged properly).
The problem is that ANY bcp error results in SQLGetDiagRec returning
SQL_NO_DATA. The same code works for the ODBC errors from the SQL* functions
,
but if any bcp_* function fails I always get SQL_NO_DATA. I am passing in th
e
connection handle with SQL_HANDLE_DBC as the handle type like the docs say,
but I have never managed to get a BCP error from this function.
Sometimes I can run the input files (I am using data and format files for
simplicity) with the command line bcp utility, and then I will see error
messages I can use. Sometimes the bcp utility works however, so I need the
error handling to find out what is going wrong. (The application is running
under COM+ as a special domain user for security reasons).
How should I use VB.NET to get the error messages when the ODBC BCP
functions fail? Why would my error handling code work for some errors but
return SQL_NO_DATA for others?Hi
I have never used this but, from your description it is hard to tell what is
failing, or even if you are using the correct error handling mechanism.
Posting sample code that can re-create your problem will help.
You may want to look at the example
http://msdn.microsoft.com/library/d...>
mp_4pm8.asp, although this is in C++.
John
"Stephen Davies" wrote:

> I have implemented a VB.NET application which uses the ODBC BCP api to bul
k
> insert data into a Microsoft SQL 2000 database. I have included error
> handling as it is important to trap and log any errors when they occur. Th
e
> import works fine, and the error handling works fine for any ODBC errors
> (server not found, login problems etc are all logged properly).
> The problem is that ANY bcp error results in SQLGetDiagRec returning
> SQL_NO_DATA. The same code works for the ODBC errors from the SQL* functio
ns,
> but if any bcp_* function fails I always get SQL_NO_DATA. I am passing in
the
> connection handle with SQL_HANDLE_DBC as the handle type like the docs say
,
> but I have never managed to get a BCP error from this function.
> Sometimes I can run the input files (I am using data and format files for
> simplicity) with the command line bcp utility, and then I will see error
> messages I can use. Sometimes the bcp utility works however, so I need the
> error handling to find out what is going wrong. (The application is runnin
g
> under COM+ as a special domain user for security reasons).
> How should I use VB.NET to get the error messages when the ODBC BCP
> functions fail? Why would my error handling code work for some errors but
> return SQL_NO_DATA for others?|||Hi,
Did you try the sample code included in SQL server setup CD? Please refer
to odbcerr.cpp for details.
http://msdn.microsoft.com/library/d...-us/odbcsql/od_
odbcsamp_4pm8.asp
Thanks & Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
| Thread-Topic: bcp api and error handling
| thread-index: AcVAmXFPVsZNNvWPT5azzwfawDXxLg==
| X-WBNR-Posting-Host: 203.57.240.95
| From: "examnotes" <chalky@.newsgroup.nospam>
| Subject: bcp api and error handling
| Date: Wed, 13 Apr 2005 19:27:02 -0700
| Lines: 21
| Message-ID: <B608ADB0-3DFC-438D-89A4-45D4582D87C1@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.programming
| Path: TK2MSFTNGXA01.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.sqlserver.programming:85683
| NNTP-Posting-Host: tk2msftngxa03.phx.gbl 10.40.2.157
| X-Tomcat-NG: microsoft.public.sqlserver.programming
|
| I have implemented a VB.NET application which uses the ODBC BCP api to
bulk
| insert data into a Microsoft SQL 2000 database. I have included error
| handling as it is important to trap and log any errors when they occur.
The
| import works fine, and the error handling works fine for any ODBC errors
| (server not found, login problems etc are all logged properly).
|
| The problem is that ANY bcp error results in SQLGetDiagRec returning
| SQL_NO_DATA. The same code works for the ODBC errors from the SQL*
functions,
| but if any bcp_* function fails I always get SQL_NO_DATA. I am passing in
the
| connection handle with SQL_HANDLE_DBC as the handle type like the docs
say,
| but I have never managed to get a BCP error from this function.
|
| Sometimes I can run the input files (I am using data and format files for
| simplicity) with the command line bcp utility, and then I will see error
| messages I can use. Sometimes the bcp utility works however, so I need
the
| error handling to find out what is going wrong. (The application is
running
| under COM+ as a special domain user for security reasons).
|
| How should I use VB.NET to get the error messages when the ODBC BCP
| functions fail? Why would my error handling code work for some errors but
| return SQL_NO_DATA for others?
||||Thanks John and Peter for your responses.
I have created a sample and in doing so found an interesting phenomenon:
The code works in a "normal" app, but when run as a COM+ component it fails
to return BCP error messages. Commenting out the "Inherits ServicedComponent
"
line causes the error messages to work. Leave it in and I get SQL_NO_DATA.
I can't see how to add attachments with Microsoft's web based newsgroup
reader, so I signed up to geocities:
http://www.geocities.com/stephenchalkydavies/VbBcp.zip
How can I get BCP error messages when running in a COM+ application?
Thanks again,
Stephen|||Hi
This may be interesting
http://support.microsoft.com/defaul...kb;en-us;319243 but
nothing to do with COM+
John|||It doesn't mention COM+, and is talking about other methods (SQLGetData)
returning SQL_NO_DATA. I am getting bcp failures and the SQLGetDiagRec call
returns SQL_NO_DATA - but only when running in COM+.
I tried installing the MDAC patch anyway just in case - but it wouldn't
install, I think because I already upgraded to MDAC 2.8 and it is for 2.7.
Any more ideas? I really need to get the error handling working.
Thanks,
Stephen
"John Bell" wrote:

> Hi
> This may be interesting
> http://support.microsoft.com/defaul...kb;en-us;319243 but
> nothing to do with COM+
> John|||Hello Stephen,
Did you try SQLGetDiagRecW? The issue might be related to Unicode?
Also, you may want to contact our Develop Support Services by telephone so
that a dedicated Support Professional can assist you on this issue.To
obtain the phone numbers for specific technology request please take a look
at the web site listed below:
http://support.microsoft.com/defaul...S;PHONENUMBERS.
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
| Thread-Topic: bcp api and error handling
| thread-index: AcVDsxEOzHtU0b+iSc6szI5qAdg/Kw==
| X-WBNR-Posting-Host: 203.57.240.95
| From: "examnotes" <chalky@.newsgroup.nospam>
| References: <B608ADB0-3DFC-438D-89A4-45D4582D87C1@.microsoft.com>
<EA1606BF-08E9-45B2-A71A-ED1FCD739434@.microsoft.com>
<A3B4D1EE-DD56-4290-919C-0ED9ECE806F8@.microsoft.com>
<1113548068.421350.42470@.o13g2000cwo.googlegroups.com>
| Subject: Re: bcp api and error handling
| Date: Sun, 17 Apr 2005 18:08:01 -0700
| Lines: 21
| Message-ID: <98CECA7A-7E8A-43AD-9426-D2AA20A1821B@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.programming
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.programming:517122
| X-Tomcat-NG: microsoft.public.sqlserver.programming
|
| It doesn't mention COM+, and is talking about other methods (SQLGetData)
| returning SQL_NO_DATA. I am getting bcp failures and the SQLGetDiagRec
call
| returns SQL_NO_DATA - but only when running in COM+.
|
| I tried installing the MDAC patch anyway just in case - but it wouldn't
| install, I think because I already upgraded to MDAC 2.8 and it is for 2.7.
|
| Any more ideas? I really need to get the error handling working.
|
| Thanks,
| Stephen
|
| "John Bell" wrote:
|
| > Hi
| >
| > This may be interesting
| > http://support.microsoft.com/defaul...kb;en-us;319243 but
| > nothing to do with COM+
| >
| > John
||||Hi Peter,
I just tried SQLGetDiagRecW, but when I enabled COM+ (by un-commenting the
"Inherits ServicedComponent" line) I got the same SQL_NO_DATA return code
that I got with SQLGetDiagRec.
What could COM+ be doing that causes bcp to lose its errors?
Yesterday I tried running an ODBC trace. Outside of COM+, I see a [DIAG]
message in the trace followed by a successful call to SQLGetDiagRec. When ru
n
in COM+ the only difference is that the [DIAG] message is not in the trace
and hence the call to SQLGetDiagRec returns SQL_NO_DATA.
Is the error message getting stored somewhere else?
Thanks,
Stephen
"Peter Yang [MSFT]" wrote:

> Hello Stephen,
> Did you try SQLGetDiagRecW? The issue might be related to Unicode?|||Hello Stephen,
I haven't found a known issue on this behavior. Please contact our Develop
Support Services by telephone on debugging/dump analysis to further
troubleshoot this issue.
Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
| Thread-Topic: bcp api and error handling
| thread-index: AcVEdfIhZtnSq5dWQby7kIwLKqtnvA==
| X-WBNR-Posting-Host: 203.57.240.95
| From: "examnotes" <chalky@.newsgroup.nospam>
| References: <B608ADB0-3DFC-438D-89A4-45D4582D87C1@.microsoft.com>
<EA1606BF-08E9-45B2-A71A-ED1FCD739434@.microsoft.com>
<A3B4D1EE-DD56-4290-919C-0ED9ECE806F8@.microsoft.com>
<1113548068.421350.42470@.o13g2000cwo.googlegroups.com>
<98CECA7A-7E8A-43AD-9426-D2AA20A1821B@.microsoft.com>
<VLbWZOARFHA.2316@.TK2MSFTNGXA02.phx.gbl>
| Subject: Re: bcp api and error handling
| Date: Mon, 18 Apr 2005 17:23:01 -0700
| Lines: 24
| Message-ID: <90CF8356-0BCF-4740-91A6-F29889FC0A24@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.programming
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.programming:517422
| X-Tomcat-NG: microsoft.public.sqlserver.programming
|
| Hi Peter,
|
| I just tried SQLGetDiagRecW, but when I enabled COM+ (by un-commenting
the
| "Inherits ServicedComponent" line) I got the same SQL_NO_DATA return code
| that I got with SQLGetDiagRec.
|
| What could COM+ be doing that causes bcp to lose its errors?
|
| Yesterday I tried running an ODBC trace. Outside of COM+, I see a [DIAG]
| message in the trace followed by a successful call to SQLGetDiagRec. When
run
| in COM+ the only difference is that the [DIAG] message is not in the
trace
| and hence the call to SQLGetDiagRec returns SQL_NO_DATA.
|
| Is the error message getting stored somewhere else?
|
| Thanks,
| Stephen
|
| "Peter Yang [MSFT]" wrote:
|
| > Hello Stephen,
| >
| > Did you try SQLGetDiagRecW? The issue might be related to Unicode?
|
|

bcp API

I would like to execute bulk copy functionality from a C++ app. Does
an API exist? I have found Bulk-Copy functions (bcp_init,
bcp_exe...) in the ODBC API, is this what I should use? And if yes,
will/is it support by SQL Server version after SQL Server 2000?

Thanks!"elizabeth" <ezelasky@.hotmail.com> wrote in message
news:78393913.0410080650.16eb7a77@.posting.google.c om...
>I would like to execute bulk copy functionality from a C++ app. Does
> an API exist? I have found Bulk-Copy functions (bcp_init,
> bcp_exe...) in the ODBC API, is this what I should use? And if yes,
> will/is it support by SQL Server version after SQL Server 2000?
> Thanks!

Yes - see "Performing Bulk Copy Operations" in Books Online. ODBC is
supported in MSSQL 2005, and the same documentation appears in the latest
available version of the MSSQL 2005 BOL:

http://www.microsoft.com/downloads/...&DisplayLang=en

Simon|||With unmanaged C++ code, you might also consider OLE DB IRowsetFastLoad.
This is what DTS uses.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"elizabeth" <ezelasky@.hotmail.com> wrote in message
news:78393913.0410080650.16eb7a77@.posting.google.c om...
>I would like to execute bulk copy functionality from a C++ app. Does
> an API exist? I have found Bulk-Copy functions (bcp_init,
> bcp_exe...) in the ODBC API, is this what I should use? And if yes,
> will/is it support by SQL Server version after SQL Server 2000?
> Thanks!

2012年2月13日星期一

Batch Insert With SQL_ATTR_PARAMSET_SIZE Slow

The following ODBC Tracing extract shows the approach used to batch insert
thousands of rows, using the SQL_PARC_BATCH feature with ODBC 3.0 over 3.520
Manager & SQL Server 2000:
SQLAllocHandle
SQLSetStmtAttr <SQL_ATTR_PARAMSET_SIZE> = 10003
SQLSetStmtAttr <SQL_ATTR_PARAM_STATUS_PTR>
SQLSetStmtAttr <SQL_ATTR_PARAMS_PROCESSED_PTR>
SQLBindParameter(...) // column-wise binding
SQLBindParameter(...) // column-wise binding
SQLBindParameter(...) // column-wise binding
SQLExecDirect "INSERT INTO TEST(SSS,NNN,DDD) VALUES(?,?,?)"
The same test is executed on Oracle, Sybase Adaptive Server Anywhere and MS
SQL Server. Unfortunately, SQL Server is ten times slower than the other two
databases. Here are the times in seconds:
Oracle 9i = 1 second
Sybase ASA 8 = 1 second
SQL Server 2000 = 10 seconds
All tests are executed on the same machine, the test table is empty before
the test is run. Why is SQL Server so slow? What's wrong here?
Spike
What transaction mode do you use (auto/manual? Is it the same for Oracle,
Sybase, and SQL Server?
"Spike" wrote:

> The following ODBC Tracing extract shows the approach used to batch insert
> thousands of rows, using the SQL_PARC_BATCH feature with ODBC 3.0 over 3.520
> Manager & SQL Server 2000:
> SQLAllocHandle
> SQLSetStmtAttr <SQL_ATTR_PARAMSET_SIZE> = 10003
> SQLSetStmtAttr <SQL_ATTR_PARAM_STATUS_PTR>
> SQLSetStmtAttr <SQL_ATTR_PARAMS_PROCESSED_PTR>
> SQLBindParameter(...) // column-wise binding
> SQLBindParameter(...) // column-wise binding
> SQLBindParameter(...) // column-wise binding
> SQLExecDirect "INSERT INTO TEST(SSS,NNN,DDD) VALUES(?,?,?)"
> The same test is executed on Oracle, Sybase Adaptive Server Anywhere and MS
> SQL Server. Unfortunately, SQL Server is ten times slower than the other two
> databases. Here are the times in seconds:
> Oracle 9i = 1 second
> Sybase ASA 8 = 1 second
> SQL Server 2000 = 10 seconds
> All tests are executed on the same machine, the test table is empty before
> the test is run. Why is SQL Server so slow? What's wrong here?
> --
> Spike

Batch Insert With SQL_ATTR_PARAMSET_SIZE Slow

The following ODBC Tracing extract shows the approach used to batch insert
thousands of rows, using the SQL_PARC_BATCH feature with ODBC 3.0 over 3.520
Manager & SQL Server 2000:
SQLAllocHandle
SQLSetStmtAttr <SQL_ATTR_PARAMSET_SIZE> = 10003
SQLSetStmtAttr <SQL_ATTR_PARAM_STATUS_PTR>
SQLSetStmtAttr <SQL_ATTR_PARAMS_PROCESSED_PTR>
SQLBindParameter(...) // column-wise binding
SQLBindParameter(...) // column-wise binding
SQLBindParameter(...) // column-wise binding
SQLExecDirect "INSERT INTO TEST(SSS,NNN,DDD) VALUES(?,?,?)"
The same test is executed on Oracle, Sybase Adaptive Server Anywhere and MS
SQL Server. Unfortunately, SQL Server is ten times slower than the other two
databases. Here are the times in seconds:
Oracle 9i = 1 second
Sybase ASA 8 = 1 second
SQL Server 2000 = 10 seconds
All tests are executed on the same machine, the test table is empty before
the test is run. Why is SQL Server so slow? What's wrong here?
--
SpikeWhat transaction mode do you use (auto/manual? Is it the same for Oracle,
Sybase, and SQL Server?
"Spike" wrote:

> The following ODBC Tracing extract shows the approach used to batch insert
> thousands of rows, using the SQL_PARC_BATCH feature with ODBC 3.0 over 3.5
20
> Manager & SQL Server 2000:
> SQLAllocHandle
> SQLSetStmtAttr <SQL_ATTR_PARAMSET_SIZE> = 10003
> SQLSetStmtAttr <SQL_ATTR_PARAM_STATUS_PTR>
> SQLSetStmtAttr <SQL_ATTR_PARAMS_PROCESSED_PTR>
> SQLBindParameter(...) // column-wise binding
> SQLBindParameter(...) // column-wise binding
> SQLBindParameter(...) // column-wise binding
> SQLExecDirect "INSERT INTO TEST(SSS,NNN,DDD) VALUES(?,?,?)"
> The same test is executed on Oracle, Sybase Adaptive Server Anywhere and M
S
> SQL Server. Unfortunately, SQL Server is ten times slower than the other t
wo
> databases. Here are the times in seconds:
> Oracle 9i = 1 second
> Sybase ASA 8 = 1 second
> SQL Server 2000 = 10 seconds
> All tests are executed on the same machine, the test table is empty before
> the test is run. Why is SQL Server so slow? What's wrong here?
> --
> Spike