SoftwareSavant
SoftwareSavant

Reputation: 9767

Keep getting an error when using OledbConnection

I can't seem to set up a connection when I attempt to open up an excel 2010 spreadsheet (xlsx file). I don't know what I am doing wrong. I appear to be following the tutorials to a T.

Here is the code I am trying...

        static string fileName = "C:\\Code\\UPMC\\ISD\\EADIS\\UPMC.ISD.EADIS.ACO.ACOBackLoad\\App_Data\\Example ACO Epic Data File.xlsx";
        try
        {
            //Workbook workBook = _excelApp.Workbooks.Open(excelFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            //Worksheet wkSheet = (Worksheet)_excelApp.Worksheets[1];
            //OLEObject oleObject = wkSheet.OLEObjects(Type.Missing);
            using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\""))
            {
                connection.Open();
            }

These are my references.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Interop.Excel;
    using System.IO;
    using System.Data;
    using System.Data.OleDb;

This would be the exception.

The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an     exception.

Message Unrecognized configuration section authentication. I get the impression I need to set up an app.config. Guess I need to find some better tutorials.

Upvotes: 0

Views: 743

Answers (1)

Cheung
Cheung

Reputation: 15552

I have same problem today after added the <appSettings> When i remove them, it works.

<appSettings> added on incorrect position will cause this error.

Upvotes: 1

Related Questions