Create Excel (xlsx) file in SSIS/C# using Microsoft.ACE.OLEDB

  • Hi,
    I am trying to execute the below mention code in a script task in SSIS (C#). I get the error {"The Microsoft Access database engine could not find the object 'C:\\test.xlsx'. Make sure the object exists and that you spell its name and the path name correctly. If 'C:\\test.xlsx' is not a local object, check your network connection or contact the server administrator."}

    If I remove IMEX=1; it works fine. Regardless how/in which context I use IMEX=1; it gives me problems. I have to use mixed data columns. What am I doing wrong?

         if (File.Exists("C:\\test.xlsx"))
           File.Delete("C:\\test.xlsx");

          string str = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\test.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\"");

          using (OleDbConnection conn = new OleDbConnection(str))
          {
           conn.Open();

           string query = "CREATE TABLE [YieldData] ( [PoolInvest 10] Text,[Jan] Text,[Feb] Text,[Mar] Text,[Apr] Text,[Maj] Text,[Jun] Text,[Jul] Text,[Aug] Text,[Sep] Text,[Okt] Text,[Nov] Text,[Dec] Text,[YTD] text)";
           using (OleDbCommand cmd = new OleDbCommand(query, conn))
           {
            cmd.ExecuteNonQuery();
           }
           conn.Close();
          }

  • Hi,
    have you ever tried  an other path?
    On your sql server we are not allowed, to create files in the root directory.
    Kind regards,
    Andreas

  • I thought that IMEX=1 was valid for reading files, not writing to them. 

    What problems do you see if you omit it?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • This was removed by the editor as SPAM

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply