. Advertisement .
..3..
. Advertisement .
..4..
I am working on csharp, but I found the following warning message:
Error CS7036 There is no
argument given that corresponds to the required formal parameter
'errorMsg' of 'ErrorEventArg.ErrorEventArg(string,
string)' MSSQLTest C:\Users\Administrator\Desktop\MSSQLTest\MSSQLTest\MSSQLConnection.cs 61
Is there any way to stabilize the issue “There is no argument given that corresponds to the required formal parameter”? I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me? Please find the beginning command below:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading;
namespace MSSQLTest
{
public class ErrorEventArg : EventArgs
{
public string ErrorMsg { get; set; }
public string LastQuery { get; set; }
public ErrorEventArg(string errorMsg, string lastQuery)
{
ErrorMsg = errorMsg;
LastQuery = lastQuery;
}
}
public class MSSQLConnection
{
/// <summary>
/// Private class objects.
/// </summary>
private SqlConnection sqlConnection;
private int sqlCommandTimeout;
private string lastQuery = string.Empty;
/// <summary>
/// Public event related objects & handler.
/// </summary>
public event ErrorHandler OnError;
public delegate void ErrorHandler(MSSQLConnection sender, ErrorEventArg e);
/// <summary>
/// Class constructor.
/// </summary>
/// <param name="sqlConnection"></param>
/// <param name="sqlCommandTimeout"></param>
public MSSQLConnection(SqlConnection sqlConnection, Int32 sqlCommandTimeout = 120)
{
if (null == sqlConnection)
throw new Exception("Invalid MSSQL Database Conection Handle");
if (sqlConnection.State != System.Data.ConnectionState.Open)
throw new Exception("MSSQL Database Connection Is Not Open");
this.sqlConnection = sqlConnection;
this.sqlCommandTimeout = sqlCommandTimeout;
}
/// <summary>
/// Helper method to emit a database error to event subscribers.
/// </summary>
/// <param name="errorMsg"></param>
internal void EmitError(String errorMsg)
{
var errorDelegate = OnError;
if (errorDelegate != null)
{
errorDelegate(this, new ErrorEventArg() // Line #61
{
ErrorMsg = errorMsg,
LastQuery = lastQuery
});
}
}
/// rest of the code snipped
}
}
The cause: Because the old MSSQL Connection helper library was refactored, or because a default constructor was not created, you get the error:
There is no argument given that corresponds to the required formal parameter
Solution: You’ve had a constructor with two parameters. You ought to write a short code like:
Alternatively, you may write a default constructor for
ErrorEventArg
that takes no parameters, such as this:The constructor of
You will need to add “base” in the following order: