PC Review


Reply
Thread Tools Rate Thread

Can't explicitly close the connection that SqlBulkCopy uses

 
 
Rami
Guest
Posts: n/a
 
      10th Feb 2009
Hi.

I am running SQL Server 2005 SP2 on Windows Server 2003.

SQL Profiler indicates "Audit Login" when WriteToServer is called but it
does not indicate "Audit Logout" until my application has exited.

It seems that SqlBulkCopy uses its own connection string and I can not
figure out how to disable connection pooling for it or explicity close the
connection.

Along with the sample code below, I also tried to create a SqlConnection,
pass it as a parameter to the SqlBulkCopy constructor, and explicitly open
and close it, but that did not work.

I also tried to call GC.Collect() but that did not close the connection
either.

Any ideas?

Thank you.

Here is the code sample:
try
{
using (SqlBulkCopy copy = new
SqlBulkCopy(this.SqlBulkCopyConnectionString,
SqlBulkCopyOptions.KeepIdentity))
{
//insert all rows
foreach (DataTable dt in ds.Tables)
{
Logger.Write("SqlBulkCopy " + dt.TableName);

copy.DestinationTableName = dt.TableName;
copy.WriteToServer(dt, DataRowState.Added);
copy.WriteToServer(dt, DataRowState.Modified);
copy.WriteToServer(dt, DataRowState.Unchanged);
}
}
}
catch (Exception ex)
{
Logger.Write(ex.ToString());

throw;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
explicitly name workbook and close without saving laavista Microsoft Excel Programming 2 15th Nov 2009 05:39 AM
Can't explicitly close the connection that SqlBulkCopy uses Rami Microsoft ADO .NET 2 10th Feb 2009 10:53 PM
Explicitly close DataReader if I close the underlying connection?" MarkusJNZ@gmail.com Microsoft Dot NET Framework 2 1st Nov 2006 05:49 AM
Do I need to close DataReader explicitly? =?Utf-8?B?TWF0dA==?= Microsoft ADO .NET 4 19th Jun 2006 04:00 PM
Close connection in webApp explicitly? Klaus Jensen Microsoft ADO .NET 1 2nd Jul 2003 05:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:26 AM.