I am facing a problem while uploading an excel sheet using oledb. Couple of weeks ago, it was working perfectly so I moved to different module.
But when I am testing and debugging the application now it is throwing an error.
Someone please look into this as I am not able to resolve this issue, also, their is no resolution posted when I searched on google as well....
Error: DisconnectedContext was Detected
Transition into COM context 0x673dd0 for this RuntimeCallableWrapper failed with the following error: The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)). This is typically because the COM context 0x673dd0 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else. Releasing the interfaces from the current COM context (COM context 0x673d18). This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.
My Code: For FileUpload
string filefullpath = null;
try
{
string filepath = Server.MapPath("~/BulkUploadFile/");
string filename = fuDatabaseFile.FileName;
string filetype = Path.GetExtension(filename);
string filenamewithoutextension = Path.GetFileNameWithoutExtension(filepath);
string append = DateTime.Now.ToString("yyyyMMddHHmmssfffFFF");
string newfilename = filenamewithoutextension + append + filetype;
filefullpath = filepath + newfilename;
fuDatabaseFile.SaveAs(filefullpath);
}
catch (Exception ex)
{
}
Code for ExcelConnectivity:
FileUpload();
string excelconnectionstring = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + FileUpload() + ";Extended Properties=Excel 12.0;Persist Security Info=False";
using (OleDbConnection excelcon = new OleDbConnection(excelconnectionstring))
{
using (OleDbCommand command = new OleDbCommand("", excelcon))
{
command.CommandText = "Select * from [Sheet1$]";
excelcon.Open();
using (OleDbDataReader reader = command.ExecuteReader())
{
DataTable table = new DataTable();
table.Columns.Add("Name");
table.Columns.Add("EmpID");
}
}
}
User contributions licensed under CC BY-SA 3.0