Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# read of xls file works on Vista home premium but not XP Pro, Vista Business or 2003 server. [modified]

C# read of xls file works on Vista home premium but not XP Pro, Vista Business or 2003 server. [modified]

Scheduled Pinned Locked Moved C#
csharphelpdatabasesysadminbusiness
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mid_life_crisis
    wrote on last edited by
    #1

    These are the relevent lines from the code. The same file is being opened, the problem is that the program can't find the sheet when running under XPPRo, 2003 server, or Vista Business. All computers are up to date with the latest .net installed, all have Excel 2003 with current updates. Any ideas? string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=Excel 8.0"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); All Systems have Excel 2003 SP3 I get an error message on the failures: System.Data.OleDbException: The Microsoft Jet database engine could not find the object 'Sheet1$'

    modified on Tuesday, February 17, 2009 12:14 PM

    M 1 Reply Last reply
    0
    • M mid_life_crisis

      These are the relevent lines from the code. The same file is being opened, the problem is that the program can't find the sheet when running under XPPRo, 2003 server, or Vista Business. All computers are up to date with the latest .net installed, all have Excel 2003 with current updates. Any ideas? string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=Excel 8.0"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); All Systems have Excel 2003 SP3 I get an error message on the failures: System.Data.OleDbException: The Microsoft Jet database engine could not find the object 'Sheet1$'

      modified on Tuesday, February 17, 2009 12:14 PM

      M Offline
      M Offline
      MickCurley
      wrote on last edited by
      #2

      Try using this as a connection string instead "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0;HDR=Yes;IMEX=1'"; I am going with the presumption that "filename" is an actual path and "Sheet1" does exist in all cases.... butyou know what they say about presumptions ;)

      M 1 Reply Last reply
      0
      • M MickCurley

        Try using this as a connection string instead "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0;HDR=Yes;IMEX=1'"; I am going with the presumption that "filename" is an actual path and "Sheet1" does exist in all cases.... butyou know what they say about presumptions ;)

        M Offline
        M Offline
        mid_life_crisis
        wrote on last edited by
        #3

        You are correct. Filename is a variable holding the full path of the actual file, and sheet1 does exist in all cases, as in each instance, I have copied the file from one to another. What is the "IMEX=1" all about?

        M 1 Reply Last reply
        0
        • M mid_life_crisis

          You are correct. Filename is a variable holding the full path of the actual file, and sheet1 does exist in all cases, as in each instance, I have copied the file from one to another. What is the "IMEX=1" all about?

          M Offline
          M Offline
          mid_life_crisis
          wrote on last edited by
          #4

          Darn! Still no good. It makes no sense to me. Why fine on one but not on others? I used to say that I liked programming because of the instant gratification when you compile an app and it works, but this is an example of the dark counterpoint to that. Instant frustration.

          M 1 Reply Last reply
          0
          • M mid_life_crisis

            Darn! Still no good. It makes no sense to me. Why fine on one but not on others? I used to say that I liked programming because of the instant gratification when you compile an app and it works, but this is an example of the dark counterpoint to that. Instant frustration.

            M Offline
            M Offline
            MickCurley
            wrote on last edited by
            #5

            HDR=Yes; Indicates that there are header rows in the sheet, and IMEX=1; 0 Export mode, 1 Import mode, 2 Linked mode, I run Imports from excel in 98/XP/Vista with that connection and its all good. How are you defining your path ie:Filename??

            M 1 Reply Last reply
            0
            • M MickCurley

              HDR=Yes; Indicates that there are header rows in the sheet, and IMEX=1; 0 Export mode, 1 Import mode, 2 Linked mode, I run Imports from excel in 98/XP/Vista with that connection and its all good. How are you defining your path ie:Filename??

              M Offline
              M Offline
              mid_life_crisis
              wrote on last edited by
              #6

              This is all the relevant code. I just don't get why it would work for the one system but not the others. string filename = "C:\\Program files\\Daily_Totals_By_Employee.xls"; string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0'"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); con.Close();

              M 1 Reply Last reply
              0
              • M mid_life_crisis

                This is all the relevant code. I just don't get why it would work for the one system but not the others. string filename = "C:\\Program files\\Daily_Totals_By_Employee.xls"; string listname = "Sheet1"; OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties = 'Excel 8.0'"); con.Open(); try { DataSet myDataSet = new DataSet(); OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + listname + "$]", con); myCommand.Fill(myDataSet); con.Close();

                M Offline
                M Offline
                MickCurley
                wrote on last edited by
                #7

                I would try to put the file in a location like "C:\\Myfolder" just to test eliminate the "Program files" directory and see what happens, also punch in the path manually Data Source= C:\Myfolder\Daily_Totals_By_Employee.xls See if any of those work...sorry I can't be any more specific...

                M 1 Reply Last reply
                0
                • M MickCurley

                  I would try to put the file in a location like "C:\\Myfolder" just to test eliminate the "Program files" directory and see what happens, also punch in the path manually Data Source= C:\Myfolder\Daily_Totals_By_Employee.xls See if any of those work...sorry I can't be any more specific...

                  M Offline
                  M Offline
                  mid_life_crisis
                  wrote on last edited by
                  #8

                  I just tried the path suggestion. I changed the path to "C:\\csharpdata\\Daily_Totals_By_Employee.xls". No change. At the risk of being obtuse, I don't understand how permissions could be the problem. I'm not saying you're all wrong, just that I don't understand it. The file is being opened: wouldn't a permissions issue prevent that? The program opens the file then fails to find the sheet.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups