Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 808717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:36:29+00:00 2026-05-15T00:36:29+00:00

I am trying to read data from excel file in asp.net. I have added

  • 0

I am trying to read data from excel file in asp.net. I have added the connection string to webConfig file:

<add name="xls" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=HPM_DB.xls;Extended Properties=Excel 8.0"/>

But it shows me an errormessage when I run this query:

string query = “Select * from [IO_Definition$]”;

IO_Definition is the name of the spreadsheet in my excel file. I also added the excel file to the App_Data folder of the website.

The error is:

The Microsoft Jet database engine could not find the object ‘IO_Definition$’. Make sure the object exists and that you spell its name and the path name correctly.

The thing is, when I write the absolute path of the excel file in the connectionString it does work. Is there anyway I can make it work without writing the absolute path?

Thanks,

Greg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:36:30+00:00Added an answer on May 15, 2026 at 12:36 am

    The issue here is that for this sort of ‘file’ connection, the OleDb provider needs, as you’ve already found, the absolute path to the file. Historically, we’ve done this with Server.MapPath, in which case you’d do something like:

    <connectionstrings>
        <add name="xls" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;"/>
    </connectionstrings>
    
    String connString;
    OleDbConnection conn;
    
    connString = Web.Configuration.WebConfigurationManager.ConnectionStrings["xls"].ConnectionString;
    connString = connString + Server.MapPath("~/App_Data/HPM_DB.xls");
    
    conn = new OleDbConnection(connString);
    
    conn.Open();
    ...
    

    which works, but you need to either do all that every time you want to open a connection and query the data, or break it out into a connection factory class.

    A neater way to do it is this:

    <connectionstrings>
        <add name="xls" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;
        Data Source=|DataDirectory|\HPM_DB.xls;"/>
    </connectionstrings>
    
    OleDbConnection conn;
    
    conn = new OleDbConnection(Web.Configuration.WebConfigurationManager.ConnectionStrings["xls"].ConnectionString);
    conn.Open();
    ...
    

    At runtime the |DataDirectory| token in the connection string acts as a macro which silently does all that Server.MapPath stuff for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.NET to read the data in the excel file. I am
I am trying to read data from excel files using datatable. The command select
I'm trying to read data from a.csv file to ouput it on a webpage
I'm trying to read an excel file from C# using COM, and can get
I'm trying to read an Excel file (.xls, I think Excel 2003 compatible) via
I'm trying to read an excel file using an OleDb Reader, I couldn't debug
I'm trying to read an Excel (xlsx) file using the code shown below. I
I'm trying to import a excel file with more than 256 columns using OLEDB
I'm working with pyODBC communicate with a MS SQL 2005 Express server. The table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.