473,583 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlBulkCopy fails during process exit

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 line-by-line while
debugging in VS. See my code below. If I call SaveTable() on my own,
before the process exits, then it executes just fine. Is there a
problem doing this during ProcessExit? I need to do the SqlBulkCopy
during process exit!

Help!

An abstraction of my code:

DataTable myDataTable;

static void Main(string[] args) {
//Catch process exit
AppDomain.Curre ntDomain.Proces sExit += new EventHandler(On Exit);

//Build the datatable...

//Process exits and OnExit is called...
}

void OnExit(object sender, EventArgs e) {
SaveTable();
}

public void SaveTable() {
//Create our bulk copy object that will import our data into SQL.
SqlBulkCopy bulk = new SqlBulkCopy("co nnection string");
bulk.Destinatio nTableName = "tablename" ;

//Column mapping is done here...

try {
bulk.WriteToSer ver(myDataTable );
}
catch (Exception e) {
TargetException (e);
}
finally {
bulk.Close();
}
}

Aug 29 '06 #1
0 1301

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

Similar topics

29
3393
by: Ken Allen | last post by:
I have a number of services developed in C# (.Net), and they have been working fine for the most part. Recently someone reported that ipon occassion (originally rarely, but more frequently on some systems of late), there is an entry in the Event Log immediately after a boot indicating that the service failed to start after 30,000 milliseconds....
17
8474
by: Jeffrey W. Baker | last post by:
Greetings, I have a 23GB data table upon which I am building a primary key of three columns. The data is mounted in a 137GB device and pg_xlog is mounted on a separate 3.5GB device. I have configured 24 checkpoint segments, which I expect gives me a worst-case usage in pg_xlog of 384MB. Unfortunately, during the CREATE INDEX, pg_xlog...
0
4599
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...
1
3622
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?
0
7895
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...
0
7826
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...
0
8182
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. ...
0
8327
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...
0
8193
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5374
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...
1
2333
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
1
1433
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1157
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.