473,382 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SQL Server 2005 native client ODBC query

Hello Guys,

I am writing a high performance win32 telemetry midleware service which uploads to SQL server in bulk frequently. I know how to do simple things in ODBC native-client.

ODBC native-client documentation is terse to say the least. I would like to know from people who have used the native client bulk upload feature what the behaviour of a bulk upload is when one of the rows causes a server-side constraint error.

Specifically:
  • Do the drivers respond with the row that fails,
  • if it does, do previously inserted rows get rolled back or can you remove the erroneous row and resume the bulk upload?

If the above doesn't make sense should I look at the ole DB api. It looks like it has higher levels of abstraction as other COM api's it looks horendously bloated and terse.
Apr 4 '08 #1
3 3206
If you are talking about the Bulk Insert utility, I imported the data to a temp table (every field varchar(200)) and then I validated the data in the temp table before moving it into production tables. If no errors occurred, I deleted the temp table record. Finally, I moved to the next record and repeated until I was done.

Hope this helps.
Apr 7 '08 #2
Hello rkeith27,

The method you mention is one way of doing it, however the ODBC(and OLE DB) drivers that come with ms-sql-server 2005 and above support bulk inserts natively. It supports the method you mention above programaticall(i,e. Without having to call the BCP utility).

Additionaly though, it supports building the rows code side by binding memory locations to columns with bcp_bind and then calling bcp_sendrow (rinse and repeat).

At appropriate points one calls bcp_batch to commit the results sent so far or bcp_done if your done. these functions can return -1 indicating an error. From this error I want to know what row caused the error so I can remove it.

I would hope these semantics are exposed by the API.But they are not hinted to anywhere I can see.
Apr 8 '08 #3
Hi Guys,

I sent this to the microsoft ODBC native client team :
I am writing an application that needs to perform bulk uploads. I want to go down the native client, program variable binding-bulk upload method.

However some of the tables I am inserting into have constraints.I need to detect any errors caused and prune the erroneous rows from my result set for application side logging.

bcp_done and bcp_batch just return -1 (according to the API) and thats just about all it says about errors and bulk uploading. I am sure you guys have accounted for this.

Do I need to go down the route of creating flat-constraint-less tables to stage my bulk uploads into and then call a stored procedure to make the insert and return the rows that failed ?

Help me out here, I am lost.
And got this response :
I believe you can get detailed error information using SQLGetDiagRec ODBC APIs once you see a failure happen by using the same HDBC that you used for performing the bulk operation. However, the catch is that once a constraint violation is detected by the server the whole batch is aborted meaning none of the rows in the batch are inserted. A low performance approach in this case could be to just have 1 row batches & on failures assume that the row caused a constraint violation (after verifying with SQLGetDiagRec calls that indeed that was the problem. There is no way for the server to ignore some type of constraints like primary key/nullness/uniqueness etc. The batch containing the violating row will be aborted & you will not be able to detect exactly which row had a problem.



The approach of doing a constraint-less insert and then filtering out the violating rows makes more sense in your scenario.
so I guess i'm gonna have to hack together a solution along the lines of what rkeith mentioned but without using the external bcp utility or varchars for the fields. :D
Apr 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andreas Lauffer | last post by:
Can anyone tell me advantages / disadvantages of DataDirect Server Wire ODBC-driver? Any experiences? What about redistribution? Andreas Lauffer, easySoft. GmbH, Germany
10
by: MVChauhan | last post by:
Hi We are planning to move over to SQL Server 2005 in near future. At the moment Website is on a seperate server then the Database. OS for both the server is Window 2003 and currently our data...
4
by: ShastriX | last post by:
Getting a weird error while trying out a query from Access 2003 on a SQL Server 2005 table. Want to compute the amount of leave taken by an emp during the year. Since an emp might be off for...
2
by: Marcus | last post by:
(Appologies if this group isn't the best place for this post) Is it possible to use DAO 3.6 to access binary data (varbinary(max)) in Sql Server 2005? I have images and sound in a Sql 2005 DB...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
9
by: fniles | last post by:
I would like to copy a table(s) from SQL Server 2005 to a CVS file and vice versa. I was thinking to use the BCP command line utility, but I have a few questions: 1. The machine where I am...
5
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had...
2
by: woakesd | last post by:
I've a query which happily returns a full set of data when run in SQL Studio but when I do the same query using IIS with Classic ASP connected via ODBC's SQL Server driver (not the native one)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.