473,748 Members | 2,467 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 14778
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...@NoSpa m.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\B inn\DTSWizard.e xe

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******** *************** ***********@d45 g2000hsc.google groups.com...
On Apr 2, 9:52 am, "TheSteph" <TheSt...@NoSpa m.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...@NoSpa m.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\B inn\DTSWizard.e xe

*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...@NoSpa m.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\B inn\DTSWizard.e xe

*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
4617
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. "Transaction (Process ID 58) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction." 1) Is it possible to do a cast of the transaction has I do below?
0
1310
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 catching the ProcessExit event (this is a console app). The problem is that calling WriteToServer as seen below will immediately exit the program WITHOUT generating any exceptions or any other notices, including if I step through the code...
2
1390
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 appreciated. Thank you, lmnorms
1
3630
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 compatibility mode. No error when targeting SQL2000 database in 8.0 compatibility mode. Is this specific to 6.5 and is there a workaround?
4
1914
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 fields: Manager, email, and phone_num. 80% of these 25k have old data that needs to be updated in the Manager, email, and phone_num fields. I have used a MkTBL query to gather the updated data and place it into a table called out. My out table is...
7
3206
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 have this temporary table, is it possible to run SQL commands against it like it were an "actual" table. To give a simplistic example, lets say I have a table in my SQL Server database called "Customers" that contains 2 columns (CustomerID,
2
2350
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 bulkcopy class and works quite well except for one problem. It doesn seem to release the memory it uses. I have found that the memory used increases quite rapidly when using this class, further more the memory is not collected even when I close...
5
1498
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 characters.
6
4332
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 am using MYSQL to connect to the database and I need to update the passwords to be encrypted using the same method as the website process. How do I update? I got this far: UPDATE users SET Password =
0
8994
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9555
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9329
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8247
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.