-2
public async Task<ActionResult> Login(Login model)
{
    ClaimsIdentity identity = null;
    bool isAuthenticated = false;
    StoredProcedure sp = new StoredProcedure(_connectionString);
    if (ModelState.IsValid)
    {
        var user = model.user.ToUpper();
        bool isUserBlackListed = model.blacklistedUser;
        DateTime banDateTime = model.blacklistedUserBanDateTime;
        sp.Check_BlackList(_connectionString, user, out isUserBlackListed, out banDateTime);

The last line is giving me a headache. I can't figure out why?

public static void Check_BlackList(string _connectionString, string Employee_Email, out bool isBlackListed, out DateTime blackListDateTime)
{
    DataTable dt = new DataTable();
    blackListDateTime = DateTime.Now.AddDays(1);
    try
    {                
        using (OracleConnection con = new OracleConnection(_connectionString))
        {
            OracleCommand cmd = new OracleCommand();
            OracleDataAdapter da = new OracleDataAdapter();
            cmd.Connection = con;
            cmd.CommandText = "CHECK_BLACKLIST";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("T1_Cursor", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("P_EMPLOYEE_USERNAME", OracleDbType.Varchar2).Value = (Employee_Email);

            da.SelectCommand = cmd;
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                isBlackListed = true;                        
                DateTime.TryParse(dt.Rows[0]["ACCOUNT_STATUS_LAST_UPDATE"].ToString(), out blackListDateTime);
            }
            isBlackListed = false;                    
        }
    }
    catch (OracleException ex)
    {
        Console.WriteLine(ex.ToString());
        isBlackListed = false;
    }
}

Severity Code Description Project File Line Suppression State Error CS0176 Member 'StoredProcedure.Check_BlackList(string, string, out bool, out DateTime)' cannot be accessed with an instance reference; qualify it with a type name instead Controllers\AuthenticationController.cs 40 Active

Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42
software is fun
  • 7,286
  • 18
  • 71
  • 129
  • 4
    Like the error says: "cannot be accessed with an instance reference". The method is static, and you are calling it as an instance method, and not a static method. Call it like StoredProcedure.Check_BlackList or remove the static modifier – Marlonchosky May 04 '20 at 02:20
  • Does this answer your question? [Member '' cannot be accessed with an instance reference](https://stackoverflow.com/questions/1100009/member-method-cannot-be-accessed-with-an-instance-reference) – devNull May 04 '20 at 02:27
  • I saw that post and it didnt help – software is fun May 04 '20 at 02:41
  • So Ii have an authentication controller and I instantiated a class called StoredProcedure. I am trying to use sp.CheckBlackList(...) but it won't allow me. I also posted the method from my Stored Procedure class for reference – software is fun May 04 '20 at 02:43

1 Answers1

1

I see, you are calling your static method using the object that you have created from the class StoredProcedure and named it as sp. But when accessing a static method, you do not need to create an instance of the class, simply you can call the method with the class name without creating an object of the class.

In your case, your method is in class StoredProcedure and what you need to do is, call it like this:

StoredProcedure.Check_BlackList(_connectionString, user, out isUserBlackListed, out banDateTime);

So, the modified method would look like below:

public async Task<ActionResult> Login(Login model)
{
        ClaimsIdentity identity = null;
        bool isAuthenticated = false;
        StoredProcedure sp = new StoredProcedure(_connectionString); //  I do not think you will need this line of code here.
        if (ModelState.IsValid)
        {

            var user = model.user.ToUpper();
            bool isUserBlackListed = model.blacklistedUser;
            DateTime banDateTime = model.blacklistedUserBanDateTime;
            StoredProcedure.Check_BlackList(_connectionString, user, out isUserBlackListed, out banDateTime);
            // other code...
        }
}

Hope it helps.

Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42