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

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.CurrentDomain.ProcessExit += new EventHandler(OnExit);

//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("connection string");
bulk.DestinationTableName = "tablename";

//Column mapping is done here...

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

Aug 29 '06 #1
0 1292

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

Similar topics

29
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...
17
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...
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. ...
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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.