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;
}
|