473,505 Members | 15,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14754
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
4592
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
1298
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
1377
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
3613
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
1897
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
3191
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
2336
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
1487
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
4313
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...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.