Hi can anybody tell what is error in following code, its running through .Net 2005 editor fine,
but when running on browser gives error:
No error message available, result code: E_FAIL(0x800040 05).
[code=cpp]
try
{
// Create Connection to Excel Workbook
OleDbConnection connection = new OleDbConnection (excelConnectio nString);
if (connection.Sta te == ConnectionState .Closed)
{
connection.Open ();
}
OleDbCommand command = new OleDbCommand("s elect Name,Age,City,P hone FROM [Data$]", connection);
// Create DbDataReader to Data Worksheet
OleDbDataReader dr = command.Execute Reader();
// SQL Server Connection String
string sqlConnectionSt ring = "Data Source=localhos t;database=demo ;user id=sa;pwd=sa";
// Bulk Copy to SQL Server
SqlBulkCopy bulkcopy = new SqlBulkCopy(sql ConnectionStrin g);
bulkcopy.Destin ationTableName = "ExcelData" ;
// bulkCopy.WriteT oServer(dr);
bulkcopy.WriteT oServer(dr);
bulkcopy.Close( );
if (!dr.IsClosed)
dr.Close();
Response.Write( "Data Imported From Xls file");
if (connection.Sta te == ConnectionState .Open)
connection.Clos e();
}
catch (Exception ex)
{
Response.Write( ex.Message);
}[/code]
but when running on browser gives error:
No error message available, result code: E_FAIL(0x800040 05).
[code=cpp]
try
{
// Create Connection to Excel Workbook
OleDbConnection connection = new OleDbConnection (excelConnectio nString);
if (connection.Sta te == ConnectionState .Closed)
{
connection.Open ();
}
OleDbCommand command = new OleDbCommand("s elect Name,Age,City,P hone FROM [Data$]", connection);
// Create DbDataReader to Data Worksheet
OleDbDataReader dr = command.Execute Reader();
// SQL Server Connection String
string sqlConnectionSt ring = "Data Source=localhos t;database=demo ;user id=sa;pwd=sa";
// Bulk Copy to SQL Server
SqlBulkCopy bulkcopy = new SqlBulkCopy(sql ConnectionStrin g);
bulkcopy.Destin ationTableName = "ExcelData" ;
// bulkCopy.WriteT oServer(dr);
bulkcopy.WriteT oServer(dr);
bulkcopy.Close( );
if (!dr.IsClosed)
dr.Close();
Response.Write( "Data Imported From Xls file");
if (connection.Sta te == ConnectionState .Open)
connection.Clos e();
}
catch (Exception ex)
{
Response.Write( ex.Message);
}[/code]
Comment