使用Access - RUN-TIME错误中的窗体上的按钮调用存储过程

时间:2014-01-14 19:40:09

标签: sql sql-server stored-procedures ms-access-2010

我使用以下代码通过单击MS Access窗体上的按钮来执行存储过程。但是,此代码会产生以下错误: 运行时错误'-2147217911(80040e09)':[Microsoft] [ODBC SQL Server驱动程序] [SQL Server] EXECUTE权限被拒绝对象'SQL_Writeback',数据库'Regulatory',架构'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

1 个答案:

答案 0 :(得分:1)

查看此MSDN链接。它告诉您如何对存储过程进行GRANT EXECUTE。

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