OleDB连接字符串,用于读取由其他用户独占打开的Excel文件

Kus*_*kar 6 oledb oledbconnection oledbexception

谁能告诉我OleDB连接字符串只是exclusively用于读取其他用户打开的Excel文件

我试过跟随连接字符串,这对我不起作用: -

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Mode=Read;Extended Properties=\"Excel 8.0;HDR=YES;ReadOnly=true;\"";
Run Code Online (Sandbox Code Playgroud)

当其他用户打开时,此连接字符串抛出以下异常: -

The Microsoft Jet database engine cannot open the file ''.  It is already opened exclusively by another user, or you need permission to view its data.
Run Code Online (Sandbox Code Playgroud)

笔记:

  1. Excel文件保留在共享上,以便多个用户可以打开它.
  2. 使用的提供程序: - Microsoft.Jet.OLEDB.4.0
  3. Excel文件类型: - MS Excel 97-2003工作表
  4. 复制文件时容许

Jim*_*Jim 0

我建议您使用后台线程每隔一段时间重试打开一个连接,当您获得与excel数据源的连接时,将所有数据读入内存并立即关闭连接,以便其他进程可以访问文件。