访问数据库的只读连接字符串 [英] Readonly connection string to an access database
问题描述
我正在尝试使用System.Data.OleDb.OleDbConnection连接到Access数据库文件.我需要以只读模式连接,因为另一个应用程序同时使用它.我可以用读/写方式连接到数据库,但没有问题,但是似乎在任何地方都找不到只读的正确字符串.
I'm trying to connect to an Access database file using a System.Data.OleDb.OleDbConnection. I need to connect in readonly mode because another application uses it at the same time. I can connect to the database in read/write no problem but can't seem to find anywhere the correct string for readonly.
我尝试过:
Provider = Microsoft.ACE.OLEDB.12.0;数据源= {0};持久安全信息= False;模式=读取
Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Mode=Read
Provider = Microsoft.ACE.OLEDB.12.0;数据源= {0};持久性安全信息= False;扩展属性="ReadOnly = true;"
Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Extended Properties="ReadOnly=true;"
谢谢.
(我应该在原始问题中提供更多信息.)
(I should have put more information in the original question.)
当它位于 local 机器上时,我可以成功连接到访问数据库,但是当我尝试使用连接字符串连接到 remote 机器上的Access数据库时,
I could connect successfully to the access database when it was on the local machine, but when I tried connecting to the access database on a remote machine with the connection string
Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;Mode=Read
我会收到以下错误:
System.Data.OleDb.OleDbException (0x80004005): The Microsoft Office Access database engine cannot open or write to the file '{0}'. It is already opened exclusively by another user, or you need permission to view and write its data.
我的应用程序在本地系统帐户下的Windows服务中运行.
My application is running in a windows service under the local system account.
推荐答案
我认为这必须由数据库管理员将控制的用户权限或记录集的不同游标类型来控制.我不认为连接字符串指定访问模式,它只是使您到达那里. ;)
I think that has to be handled either by user permissions that the DB admin would control, or with different cursor types for your recordsets, which you would control. I don't think the connection string specifies access mode, it just gets you there. ;)
这篇关于访问数据库的只读连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!