使用 OledbConnection 时不断出现错误
当我尝试打开 Excel 2010 电子表格(xlsx 文件)时,我似乎无法建立连接。我不知道我做错了什么。我似乎正在严格遵循教程。
这是我正在尝试的代码...
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();
}
这些是我的参考资料。
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;
这将是一个例外。
The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.
信息 无法识别的配置节身份验证。 我的印象是我需要设置一个app.config。我想我需要找到一些更好的教程。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加后,我今天遇到了同样的问题
当我删除它们时,它就起作用了。
<应用程序设置>添加到不正确的位置会导致此错误。
I have same problem today after added the <appSettings>
When i remove them, it works.
<appSettings> added on incorrect position will cause this error.