无法在.NET中运行存储过程

时间:2014-01-20 03:41:26

标签: mysql procedure

我能够在MySQL Workbench中运行存储过程。当我在.NET中调用存储过程时,我收到了这个错误。

错误消息: Error ReturnDatatable():SELECT命令被拒绝用户'Admin'@'203.116.84.134'表'proc'

但是,用户是正确的,因为它可以从MySQL Work Bench中正常运行。是否需要设置一些.NET配置设置?

.NET代码如下所示。

<DataObjectMethod(DataObjectMethodType.Select)> _
    Public Shared Sub Calculate(ByVal USER_ID As Integer)

        Dim objDBProvider As DbProviderFactory = DbProviderFactories.GetFactory(ConfigSettings.ProviderName)
        Dim objDBConnection As DbConnection = objDBProvider.CreateConnection()
        Dim objDBCommand As DbCommand = Nothing
        Dim objDBDataAdaptor As DbDataAdapter = Nothing
        Dim objDBParameter As DbParameter = Nothing
        Dim int As Integer = 0

        Try
            objDBConnection.ConnectionString = ConfigSettings.ConnectionString
            objDBConnection.Open()
        Catch ex As Exception
            Throw New Exception("Error ReturnDatatable(): " & ex.Message)
        End Try

        Try
            objDBCommand = objDBProvider.CreateCommand()

            objDBCommand.Connection = objDBConnection
            objDBCommand.CommandText = "fullCalculation"
            objDBCommand.CommandType = CommandType.StoredProcedure

            objDBParameter = CreateParameter(objDBCommand, "USER_ID", DbType.Int32, USER_ID)
            objDBCommand.Parameters.Add(objDBParameter)

            int = Convert.ToUInt32(objDBCommand.ExecuteScalar())

            objDBCommand.Connection = objDBConnection
            objDBCommand.ExecuteNonQuery()


        Catch ex As Exception
            Throw New Exception("Error ReturnDatatable(): " & ex.Message)
        End Try
    End Sub

1 个答案:

答案 0 :(得分:0)

我在mySQL工作台中将其作为ROOT运行,看起来似乎已修复:

GRANT SELECT ON mysql.proc TO `Admin`@`%`;

我仍然不理解它背后的理性,但我认为管理员用户以前在存储过程中被拒绝了SELECT访问,奇怪的问题。

灵感:Protect Stored Procedure

相关问题