[OleDbException (0x80004005) RRS feed

  • Discussion générale

  • Hii, i'm trying to upload an excel sheet in my database but i get [OleDbException (0x80004005),  i have renamed the sheet Sheet1 but it's still the same Exeception,i have have read about this exception that it's a BOGUE : Le pilote ODBC Excel ignore les paramètres FirstRowHasNames et Header : but i was wondring if there is any solution for this Exception cause i really need it since i'm working in an application on MVC Model , and i have to import the Excel data in my data base,
    and when i'm trying to test this code:

    Upload Controller

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Data.OleDb;
    using System.Data;

    namespace testsmltp.Controllers
    public class UploadController : Controller
    public ActionResult Index()
    return View();

    public ActionResult Index(HttpPostedFileBase excelFile)

    if (excelFile != null)
    //Save the uploaded file to the disc.
    string savedFileName = "~/UploadedExcelDocuments/" + excelFile.FileName;

    //Create a connection string to access the Excel file using the ACE provider.
    //This is for Excel 2007. 2003 uses an older driver.
    var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0;", Server.MapPath(savedFileName));

    //Fill the dataset with information from the Hoja1 worksheet.
    var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
    var ds = new DataSet();
    adapter.Fill(ds, "results");
    DataTable data = ds.Tables["results"];

    //Create a new list of People.
    var people = new List<Person>();

    for (int i = 0; i < data.Rows.Count - 1; i++)
    Person newPerson = new Person();
    newPerson.Id = data.Rows[i].Field<double?>("Id");
    newPerson.Name = data.Rows[i].Field<string>("Name");
    newPerson.LastName = data.Rows[i].Field<string>("LastName");
    newPerson.DateOfBirth = data.Rows[i].Field<DateTime?>("DateOfBirth");


    return View("UploadComplete", people);

    return RedirectToAction("Error", "Upload");


    public ActionResult Error()
    return View();


    i get this Eception:

    Erreur du serveur dans l'application '/'.
    'Sheet1$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
    Description : Une exception non gérée s'est produite au moment de l'exécution de la requête Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code.

    Détails de l'exception: System.Data.OleDb.OleDbException: 'Sheet1$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

    Erreur source:

    Ligne 39 : var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
    Ligne 40 : var ds = new DataSet();
    Ligne 41 : adapter.Fill(ds, "results");
    Ligne 42 : DataTable data = ds.Tables["results"];
    Ligne 43 : 

    Fichier source : C:\Users\Alaeddine\documents\visual studio 2010\Projects\testsmltp\testsmltp\Controllers\UploadController.cs Ligne : 41

    Trace de la pile:

    [OleDbException (0x80004005): 'Sheet1$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.]
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1108356
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
    System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +189
    System.Data.OleDb.OleDbCommand.ExecuteCommand(Commandbehavior behavior, Object& executeResult) +58
    System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(Commandbehavior behavior, String method) +162
    System.Data.OleDb.OleDbCommand.ExecuteReader(Commandbehavior behavior) +110
    System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(Commandbehavior behavior) +4
    System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, Commandbehavior behavior) +140
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, Commandbehavior behavior) +316
    System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
    testsmltp.Controllers.UploadController.Index(HttpPostedFileBase excelFile) in C:\Users\Alaeddine\documents\visual studio 2010\Projects\testsmltp\testsmltp\Controllers\UploadController.cs:41
    lambda_method(Closure , ControllerBase , Object[] ) +180
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
    System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
    System.Web.Mvc.Controller.ExecuteCore() +106
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
    System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9652236
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

    so any help please cause i'm getting confused if i'll find a solution for this exception or not?

    • Type modifié Aurel Bera lundi 4 février 2013 08:10 Discussion
    vendredi 1 février 2013 09:21