I am using the following code to simply execute a Stored Procedure by clicking a button on an MS Access Form. However, this code produces the following error: Run-time error '-2147217911 (80040e09)': [Microsoft][ODBC SQL Server Driver][SQL Server] The EXECUTE permission was denied on the object 'SQL_Writeback', database 'Regulatory', schema 'dbo' Does anyone have some insight?
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
Check out this MSDN link. It tells you how to GRANT EXECUTE for a stored procedure.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.