[英]mdb file oledbconnection throws “The Microsoft Access database engine cannot open or write to the file …”
I'm writing a .Net Web Api that tries to read a .mdb file from a shared drive. 我正在编写一个.Net Web Api,尝试从共享驱动器读取.mdb文件。 But whenever I try to open the connection it gives me a
但是每当我尝试打开连接时,它都会给我一个
The Microsoft Access database engine cannot open or write to the file '\\myshareddrive\\thedatabase.mdb'.
Microsoft Access数据库引擎无法打开或写入文件'\\ myshareddrive \\ thedatabase.mdb'。 It is already opened exclusively by another user, or you need permission to view and write its data.
它已经由另一个用户专门打开,或者您需要权限才能查看和写入其数据。
I've already changed my permissions on the folder and the file that involves the NETWORK SERVICE account to have modify access. 我已经更改了对文件夹和涉及NETWORK SERVICE帐户的文件的权限,以具有修改访问权限。 I also messed with the IIS to "Connect as" a user that has admin rights on the shared drive.
我还搞砸了IIS,以“连接为”对共享驱动器具有管理员权限的用户。 And yes the file is closed.
是的,文件已关闭。 Not sure where to go now.
不确定现在要去哪里。 Any advice is appreciated.
任何建议表示赞赏。
I looked at this solution: 我看着这个解决方案:
http://www.aspdotnet-suresh.com/2013/01/c-microsoft-office-access-database.html http://www.aspdotnet-suresh.com/2013/01/c-microsoft-office-access-database.html
Here's my code: 这是我的代码:
var databaseStringthatincludespath = "\\myshareddrive\thedatabase.mdb"
var connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=" + databaseStringthatincludespath;
try
{
OleDbConnection Myconnection = new OleDbConnection(connString);
Myconnection.Open();
Myconnection.Close();
return "Yo test return!";
}
catch (Exception ex)
{
var error = ((ex.InnerException != null) ? ex.InnerException.Message : " ") + " -- " + ex.Message;
return error;
}
Finally figured it out. 终于想通了。 Basically you need to make sure the "Authentication" of the app on your IIS to enable impersonation (at least this is the route I took).
基本上,您需要确保IIS上应用程序的“身份验证”以启用模拟功能(至少这是我采用的方法)。 And make sure that the accoutn is recognized on the server where the path lies so that when the app gets executed as the impersonated account there won't be any issues.
并确保在路径所在的服务器上识别出accoutn,以便当应用程序作为模拟帐户执行时不会有任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.