编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

插入访问权限-无法更新.数据库或对象是只读的:Insert Into Access - Cannot Update. Database or object is read-only

jeiea 数据库/缓存 2022-5-11 10:53 8人围观

腾讯云服务器
插入访问权限-无法更新.数据库或对象是只读的的处理方法

我正尝试通过下面的VBA代码将Excel 2013中的值表上传到Access 2013数据库中.但是,我不断收到错误消息.该错误发生在cn.execute SQL行上.

I'm trying to upload a table of values from Excel 2013 into Access 2013 database via the VBA code below. However, I keep getting an error. The error occurs on the cn.execute SQL line.

运行时错误'-2147217911(80040e09)':

Run-time error '-2147217911 (80040e09)':

无法更新.数据库或对象是只读的.

Cannot update. Database or object is read-only.

我已经检查了文件和Access数据库的权限,并且它具有读写访问权限.我什至尝试在其他目录中创建一个新的Microsoft Access数据库,但得到相同的错误.

I have checked permissions on the file and Access database and and it is read and write access. I've even tried to create a new microsoft Access database in a different directory but get the same error.

让我感到难过的另一件事是,我之前在没有其他Excel工作表的情况下重用了此代码,但在此工作簿/数据库中使用它却无法正常工作.

Another thing that has me stumped is that I've re-used this code before without any problems in a different Excel sheet, but using it with this workbook/database does not work.

Sub uploadToDB() Dim SQL As String dbPath = "C:\Users\john.smith\Desktop\database.accdb" wbName = "C:\Macros\" & ActiveWorkbook.Name & ".xlsm" wsname = "Staging" TableName = "dataTable" Set cn = CreateObject("ADODB.Connection") scn = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & dbPath cn.Open scn 'find number of data points to add row = Sheets(wsname).Range("A1").End(xlDown).row SQL = "INSERT INTO " & TableName & " ([field1],[field2],[field3],[field4],[field5],[field6],[field7],[field8]) " SQL = SQL & "SELECT * FROM [Excel 12.0 Macro;HDR=YES;DATABASE=" & wbName & "].[" & wsname & "$A1:H" & row & "]" '" & wsName cn.Execute SQL cn.Close Set cn = Nothing End Sub 

问题解答

请考虑这些.其中之一可能会导致此问题:

Please condsider these. One of them might cause this issue:

  • 您使用了OpenDatabase方法并打开了数据库只读访问.

  • You used the OpenDatabase method and opened the database for read-only access.

在Microsoft Visual Basic中,您正在使用数据控件,然后将ReadOnly属性设置为True.

In Microsoft Visual Basic, you are using the Data control, and you set the ReadOnly property to True.

数据库文件在操作系统中或由您的网络定义为只读.

The database file is defined as read-only in the operating system or by your network.

数据库文件存储在只读介质上.

The database file is stored on read-only media.

在网络环境中,您没有数据库文件的写特权.

In a network environment, you do not have write privileges for the database file.

使用受保护的数据库时,数据库或其对象之一(例如字段或表)可以设置为只读.你可以没有权限使用您的用户名访问此数据,并且密码.

When working with a secured database, the database or one of its objects (such as a field or table) may be set to read-only. You may not have permission to access this data with your user name and password.

来源此处.

这篇关于插入访问权限-无法更新.数据库或对象是只读的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^