[英]c# Program gets an error using Microsoft.Jet.OLEDB.4.0 after connection open MDAC 2,6 or later is required
An old C# program no longer works to read an MS-Access database through Jet.OLE.DB.旧的 C# 程序不再适用于通过 Jet.OLE.DB 读取 MS-Access 数据库。 Also a new compilation without any changes of the source code didn't help.
此外,没有对源代码进行任何更改的新编译也无济于事。
My laptop is running Windows 10 and the MS Office is LTSC Professional Plus 2021 32-bit.我的笔记本电脑运行的是 Windows 10,MS Office 是 LTSC Professional Plus 2021 32 位。
I uninstalled Office LTSC 64-bit to install Office LTSC 32-bit and am trying to fix the problem installing the following recommended runtime packages:我卸载了 Office LTSC 64 位以安装 Office LTSC 32 位并尝试解决安装以下推荐运行时包的问题:
Our customer uses MS Access because he has linked thousands of macros in Excel with Access and switching to other databases is not possible.我们的客户使用 MS Access,因为他已将 Excel 中的数千个宏与 Access 链接起来,并且无法切换到其他数据库。
It wasn't possible to use OLE in the current Windows 10 OS 64bit environment and that's why I switched to ODBC and it works.在当前的 Windows 10 OS 64 位环境中无法使用 OLE,这就是我切换到 ODBC 并且它可以工作的原因。
I gave up using Visual Studio 2022 and switched to ACE for now because VS 2022 is really weird.我放弃了使用 Visual Studio 2022,暂时改用 ACE,因为 VS 2022 真的很奇怪。 I tried updating the current VS 2017 project but I couldn't select a.NET Frame higher than 4.8.
我尝试更新当前的 VS 2017 项目,但我不能 select a.NET Frame 高于 4.8。 I created a new project and then I could select.NET 6 or 7 if I would select "Windows Forms App" instead of "Windows Forms App .NET Framework)" but the toolbox is empty.
我创建了一个新项目,然后我可以选择 .NET 6 或 7,如果我愿意 select“Windows Forms App”而不是“Windows Forms App .NET Framework)”但工具箱是空的。
/*old code*/
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Datenbank + ";";
OleDbConnection conn = new OleDbConnection(connStr);
String strCommand = "SELECT * FROM Tickets WHERE [Ticket_Nummer] = @Ticket_Nummer";
OleDbDataAdapter da = new OleDbDataAdapter(strCommand, conn);
da.SelectCommand.Parameters.Add("@Ticket_Nummer", OleDbType.Integer).Value = Ticket_Nummer;
/*new code*/
string connStr = "Driver={Microsoft Access Driver (*.mdb)};"
+ "Dbq="+ Datenbank+";Uid=Admin;Pwd=;";
OdbcConnection conn = new OdbcConnection(connStr);
String strCommand = "SELECT * FROM Tickets WHERE [Ticket_Nummer] = ?";
OdbcDataAdapter da = new OdbcDataAdapter(strCommand, conn);
da.SelectCommand.Parameters.Add("@Ticket_Nummer", OdbcType.Numeric).Value = Ticket_Nummer;
/*rest code*/
DataSet DataSet = new DataSet();
da.Fill(DataSet, "TICKET");
DataTable dataTable = DataSet.Tables[0];
DataTableReader dr = new DataTableReader(dataTable);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.