簡體   English   中英

使用Access中的表單上的按鈕調用存儲過程-運行時錯誤

[英]Calling a Stored Procedure with a button on a form in Access - RUN-TIME Error

我使用以下代碼通過單擊MS Access Form上的按鈕來簡單地執行存儲過程。 但是,此代碼產生以下錯誤:運行時錯誤'-2147217911(80040e09)':[Microsoft] [ODBC SQL Server驅動程序] [SQL Server]對對象“ SQL_Writeback”,數據庫“ Regulatory”的EXECUTE權限被拒絕,架構'dbo'有人有見識嗎?

 Private Sub Image_RefreshButton_Click()

 Dim cnn As ADODB.Connection
 Dim rst As ADODB.Recordset
 Dim cmd As ADODB.Command
 Dim strSQL As String

 ' Instantiate the connection object
 Set cnn = New ADODB.Connection

 ' Open the connection based on the strConnect connect string arguments
     With cnn
         .ConnectionString = cSQLConn
         .Open
End With

 ' Instantiate the command object
 Set cmd = New ADODB.Command

 ' Assign the connection and set applicable properties
 cmd.ActiveConnection = cnn
 cmd.CommandText = "dbo.SQL_WriteBack"
 cmd.CommandType = adCmdStoredProc


 ' Instantiate the recordset object by using the return value
 ' of the command's Execute method. Supply the parameters by
 ' packing them into a variant array
 Set rst = cmd.Execute()

 MsgBox "All manual entries had been updated."

 Set rst = Nothing
 Set cnn = Nothing
 Set cmd = Nothing
 End Sub

查看此MSDN鏈接。 它告訴您如何授予存儲過程許可。

http://technet.microsoft.com/en-us/library/ms345484.aspx

-- Use sample database
USE AdventureWorks2012; 
GO

-- Give user [Recruiting11] rights to execute SP.
GRANT EXECUTE ON OBJECT::HumanResources.uspUpdateEmployeeHireInfo
    TO Recruiting11;
GO

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM