Domanda

I was able to run a stored procedure in MySQL Workbench. When I called the stored procedure in.NET, I got this error.

ERROR MESSAGE: Error ReturnDatatable(): SELECT command denied to user 'Admin'@'203.116.84.134' for table 'proc'

But, the user is correct, as it runs properly from the MySQL Work Bench. Is there some .NET configuration setting that needs to be set?

The .NET code is shown below.

<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
È stato utile?

Soluzione

I run this in mySQL workbench as ROOT and it seem fixed:

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

I still don't understand the rational behind it, but I think apparently Admin user was denied SELECT access on stored procedure previously, odd problem.

Inspiration: Protect Stored Procedure

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top