Jump to content

.AdoFactoryManager.GetFactory().CreateCommand() does not initialize params


Recommended Posts

VB6 code:

	If svrqAuthorise Is Nothing Then
        lvstrSQL = ""
        ASQL lvstrSQL, "UPDATE tblEEntityDuplicates"
        ASQL lvstrSQL, "SET"
        ASQL lvstrSQL, "AuthorisedBy1 = " & FormatSQL(pvobjContext.UserID) & ","
        ASQL lvstrSQL, AuditSQL(pvobjContext, ecSQLbuilder.UpdateModifyFields) & ","
        ASQL lvstrSQL, "ProcessStatus = 1 ,"
        ASQL lvstrSQL, "ProcessStatusMessage = 'Authorised 1'"
        ASQL lvstrSQL, "WHERE EntityRefToMoveFrom = ?"
        Set svrqAuthorise = New ADODB.Command
        svrqAuthorise.CommandText = lvstrSQL
        svrqAuthorise.ActiveConnection = pvobjContext.Connection
    End If

    svrqAuthorise.Parameters(0) = mvlngEntityRefToMoveFrom

Generated code:

if (svrqAuthorise_Authorise1 == null)
	lvstrSQL = "";
	UCommon.ASQL(ref lvstrSQL, "UPDATE tblEEntityDuplicates");
	UCommon.ASQL(ref lvstrSQL, "SET");
	//UPGRADE_WARNING: (1068) FormatSQL() of type Variant is being forced to string. More Information: https://www.mobilize.net/vbtonet/ewis/ewi1068
	// EWI Solution Progress: EWI ID:1068 Status: TODO Fixed By: Asmita Date: 03/10/2019
	UCommon.ASQL(ref lvstrSQL, "AuthorisedBy1 = " + Convert.ToString(UCommon.FormatSQL(pvobjContext.UserID)) + ",");
	UCommon.ASQL(ref lvstrSQL, UContext.AuditSQL(pvobjContext, UEnums.ecSQLbuilder.UpdateModifyFields) + ",");
	UCommon.ASQL(ref lvstrSQL, "ProcessStatus = 1 ,");
	UCommon.ASQL(ref lvstrSQL, "ProcessStatusMessage = 'Authorised 1'");
	UCommon.ASQL(ref lvstrSQL, "WHERE EntityRefToMoveFrom = ?");
	svrqAuthorise_Authorise1 = UpgradeHelpers.DB.AdoFactoryManager.GetFactory().CreateCommand();
	svrqAuthorise_Authorise1.CommandText = lvstrSQL;
	svrqAuthorise_Authorise1.Connection = pvobjContext.Connection;

svrqAuthorise_Authorise1.Parameters[0].Value = mvlngEntityRefToMoveFrom;

The problem is parameters array is no initialized in converted code so it leads to a runtime exception.

How can I solve it in a way I don't need to go over every database access method and manually initialize parameters?

Best regards!

Link to comment
Share on other sites

  • Mobilize.Net Staff


The VB6 code needs to add the parameter to the parameter collection before accessing the value of the parameter otherwise an error at runtime is generated.

The vb6 code does not indicate how the parameter at the index 0 of the collection is created, without that the followin line in the VB6 code will crash at runtime because there's no parameter at index 0.

svrqAuthorise.Parameters(0) = mvlngEntityRefToMoveFrom

When that code is converted to C#, a similiar situation happens, if the parameter is not created and added to the parameter collection a crash is generated. 

In this case the creation of the parameter is not incuded in the VB6 code.

The situation described here is not necesarrily an issue with the converted code but it could be related to a problem in the source code.

To determine what is causing it's important to check when the parameter at index 0 is created and added to the parameter collection. 


Edited by OlmanQuesada
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use