473,383 Members | 1,813 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,383 software developers and data experts.

Looking for a SqlBulkCopy that can do UPDATE...

Using : MS-SQL 2005 / .NET 2.0 / VS2005

I have two server with the same database def but different data.

I would like to import data from Server2.TableA to Server1.TableA. If a row
doesn't exists on Server1.TableA, it should be added; if the data already
exists it should be updated.

I have to write a C# application do this operation on a daily basis on about
50 different tables.

- SqlBulkCopy : doesn't works because it can only do INSERT.
- DataTable.Load() : doesn't works because the destination table should be
entirely loaded into memory and it's too much data with some table.

I'm looking for something like SqlBulkCopy but it should handle the
UDPATE.

Does anybody have a simple solution to this problem ?

Thanks for your help !

Steph.
Apr 2 '08 #1
5 14745
A staging table... use SqlBulkCopy to throw the data into the twin,
then use an SP to do the merge. In SQL Server 2008 there is also a
MERGE syntax for exactly this case, but until then you'll need an
INSERT (where not exists), an UPDATE (inner join) and a DELETE (where
not exists, other way around).

Marc
Apr 2 '08 #2
On Apr 2, 9:52*am, "TheSteph" <TheSt...@NoSpam.comwrote:
Using : MS-SQL 2005 / .NET 2.0 / VS2005

I have two server with the same database def but different data.

I would like to import data from Server2.TableA to Server1.TableA. If a row
doesn't exists on Server1.TableA, it should be added; if the data already
exists it should be updated.

I have to write a C# application do this operation on a daily basis on about
50 different tables.

* - SqlBulkCopy : doesn't works because it can only do INSERT.
* - DataTable.Load() : doesn't works because the destination table should be
entirely loaded into memory and it's too much data with some table.

* I'm looking for something like SqlBulkCopy but it should handle the
UDPATE.

* *Does anybody have a simple solution to this problem ?

* * *Thanks for your help !

* * *Steph.
I have something similar to your escenario and this is what I do.
I do use DTS , not sqlbulk, to do the copying.
I do the copying to a temp table (staging table) in the DB
The last step in the app (after executing the DTS) is to execute a SP
that insert/update/delete the real table based on the imported table.

The only problem with that solution though, is that SQL Express 2005
does not support DTS so I have to use MSDE
Apr 2 '08 #3
Thanks for your advices !

I read that you don't have DTS in you SQL Express 2005. but in fact there is
a [hidden] way to have DTS in SQL Express 2005 :

Just Download SQL Express 2005 "TOOLKIT Edition" on MS Web site (the file is
: SQLEXPR_TOOLKIT.EXE). Install it on your computer. The DTS Wizard will be
installed in this path : C:\Program Files\Microsoft SQL
Server\90\DTS\Binn\DTSWizard.exe

You can easily add it in the Tool menu of the SQL Management Studio
Express.

Steph.
"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:2a**********************************@d45g2000 hsc.googlegroups.com...
On Apr 2, 9:52 am, "TheSteph" <TheSt...@NoSpam.comwrote:
Using : MS-SQL 2005 / .NET 2.0 / VS2005

I have two server with the same database def but different data.

I would like to import data from Server2.TableA to Server1.TableA. If a
row
doesn't exists on Server1.TableA, it should be added; if the data already
exists it should be updated.

I have to write a C# application do this operation on a daily basis on
about
50 different tables.

- SqlBulkCopy : doesn't works because it can only do INSERT.
- DataTable.Load() : doesn't works because the destination table should be
entirely loaded into memory and it's too much data with some table.

I'm looking for something like SqlBulkCopy but it should handle the
UDPATE.

Does anybody have a simple solution to this problem ?

Thanks for your help !

Steph.
I have something similar to your escenario and this is what I do.
I do use DTS , not sqlbulk, to do the copying.
I do the copying to a temp table (staging table) in the DB
The last step in the app (after executing the DTS) is to execute a SP
that insert/update/delete the real table based on the imported table.

The only problem with that solution though, is that SQL Express 2005
does not support DTS so I have to use MSDE
Apr 2 '08 #4
On Apr 2, 11:50*am, "TheSteph" <TheSt...@NoSpam.comwrote:
Thanks for your advices !

I read that you don't have DTS in you SQL Express 2005. but in fact there is
a [hidden] way *to have DTS in SQL Express 2005 :

Just Download SQL Express 2005 "TOOLKIT Edition" on MS Web site (the file is
: SQLEXPR_TOOLKIT.EXE). Install it on your computer. The DTS Wizard will be
installed in this path : C:\Program Files\Microsoft SQL
Server\90\DTS\Binn\DTSWizard.exe

*You can easily add it in the Tool menu of the SQL Management Studio
Express.
Hi,
Thanks for the tip !!!!
I will look into it
Apr 2 '08 #5
On Apr 2, 11:50*am, "TheSteph" <TheSt...@NoSpam.comwrote:
Thanks for your advices !

I read that you don't have DTS in you SQL Express 2005. but in fact there is
a [hidden] way *to have DTS in SQL Express 2005 :

Just Download SQL Express 2005 "TOOLKIT Edition" on MS Web site (the file is
: SQLEXPR_TOOLKIT.EXE). Install it on your computer. The DTS Wizard will be
installed in this path : C:\Program Files\Microsoft SQL
Server\90\DTS\Binn\DTSWizard.exe

*You can easily add it in the Tool menu of the SQL Management Studio
Express.

Steph.
I just found it and I'm downloading as we speak, I also found the
existence of SQL Express with Advanced Services, I had no idea such a
product was available, wonder if it's a public fact that they are
available?

Did anybody hear about it? Or maybe it was available from the
beggining and I had no idea
Apr 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Oscar Thornell | last post by:
Hi, I am trying to enlist an instance of SqlBulkCopy into a transaction. When I executes and try to write to the database IŽll get an exception indicating a transactional deadlock. ...
0
by: Cwappy | last post by:
I have a class that builds a DataTable and then, when the process is exiting, tries to write that DataTable to SQL Server 2000 via the SqlBulkCopy class. I know the process is exiting because I'm...
2
by: lmnorms1 | last post by:
Hello, I am looking to update a record that was read in with OleDbDataReader. I have the record in reader but now with the reader connection open; how do I update it. Any advice would be...
1
by: harleedavidson | last post by:
Using SqlBulkCopy.WriteToServer to upload a datatable and getting: System.Data.SqlClient.SqlException Line 1: Incorrect syntax near 'COLLATE'. Database Server is SQL2000, database in in 6.5...
4
MitchR
by: MitchR | last post by:
Good Morning; I have an issue that I need to guidance to resolve. I have a table called return_tbl with about 25k records. I have 23 Fields in this table. I am looking to update 3 of these 23...
7
by: Matt | last post by:
So as you all know the great thing about ADO.NET is that I can take an entire table from a database and dump it into an in memory datatable using ADO.NET. Well my question is that now that I...
2
by: Amar | last post by:
Hi, I need to insert a large amount of records pretty frequently through my application. The quickest way to achive this seems to be SQLBulkcopy class. I have implemented the solution using the...
5
by: artemetis | last post by:
Simple, I'm sure... I'm trying to run an update query, where I am looking to update "/" with "-". I can't figure out how to set the criteria/update to fields correctly for these special...
6
by: Matt Rose | last post by:
Update a MYSQL db password using crypt() technology on MYSQL connection. I am looking to update a user table of passwords that were inserted without using crypt() on a Perl development project. I...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.