ASP.NET Connection to DB forcibly closed when importing data into table

I am using C# Visual Studio 2005 and SQL Server 2005.

Before I implemented Role Management in the ASP.NET Configuration Tool, my import of data from an Excel spreadsheets worked fine. But after I implemented Role Management, every time I tried to import data from my excel spreadsheet, the connection will be forcibly closed.

Below is a code snippet of my excel import:

string strUploadFileName = "C:/Documents and Settings/user01/My Documents/Visual Studio 2005/WebSites/MajorProject/UploadFiles/" + DateTime.Now.ToString("yyyyMMddHHmmss") + strExtension;


string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strUploadFileName + ";Extended Properties=Excel 8.0;";

using (OleDbConnection connection = new OleDbConnection(connStr))
   OleDbCommand command = new OleDbCommand("Select [COLUMNS] FROM [sheet1$]", connection);


   using (DbDataReader dr = command.ExecuteReader())
       string sqlConnectionString = "Data Source=<DS>";

       using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
          bulkCopy.DestinationTableName = "UserData";

Anyone know what might be the possible reasons? I have turned off my role management for my web application and waiting for my server to restart and I will try to import data into my table again.

Thank you in advance for any help.


You may need to close the connection when data is read. The using way can only help to dispose the object connection,but not to close it.

Wish it would help.

Need Your Help

Enabling Double Buffering

winforms visual-studio-2008 doublebuffered

I've seen the following code to enable double buffering on a winform:

How do Adobe PhoneGap and Apache Cordova differ?

cordova mobile

So far, I haven't been able to find a "plain English" explanation of the difference between Apache Cordova and PhoneGap, and when to use either of them.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.