Call Stored Procedure from Navision (DotNet Variable)

 

SQLCommand := SQLCommand.SqlCommand();
SQLCommand.CommandType := SQLCommand.CommandType.StoredProcedure;
SQLConnection := SQLConnection.SqlConnection(‘Server=’+’SERVERNAME’+’;’
+ ‘Database=’+’DB Name’+’;’
+ ‘Uid=’+’UID’+’;’
+ ‘Pwd=’+’PWD’+’;’);
SQLConnection.Open;

SQLCommand.CommandText(‘Metro_InsertUpdateOrderInfoEventTriggered’);
SQLCommand.Connection := SQLConnection;

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P1’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= eventcode;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P2’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= 0;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P3’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= 0;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P4’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= 0;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P5’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= WebUserId;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P6’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= NoOfOrder;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P7’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= TriggerModule;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P8’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= TriggerSource;
SQLCommand.Parameters.Add(SqlParamCycleCode);
SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@ActionUser’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= ActionUser;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P9’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= OrderNo;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P10’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= Custno;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P11’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= ”;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P12’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= ”;
SQLCommand.Parameters.Add(SqlParamCycleCode);

SqlParamCycleCode := SqlParamCycleCode.SqlParameter();
SqlParamCycleCode.ParameterName := ‘@P13’;
SqlParamCycleCode.DbType := SQLDbType.String;
SqlParamCycleCode.Direction := SqlParamCycleCode.Direction.Input;
SqlParamCycleCode.Value:= ”;
SQLCommand.Parameters.Add(SqlParamCycleCode);
SQLCommand.ExecuteNonQuery;

SQLConnection.Close;
CLEAR(SQLCommand);
CLEAR(SQLConnection);
SQLConnection – System.Data.SqlClient.SqlConnection.’System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

SQLCommand – System.Data.SqlClient.SqlCommand.’System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

SqlParamCycleCode – System.Data.SqlClient.SqlParameter.’System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

SQLDbType – System.Data.DbType.’System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

Advertisements

2 comments on “Call Stored Procedure from Navision (DotNet Variable)

  1. Hi,
    I use the above code and am getting the below mentioned error while calling SP from navision either manually or using job queue.

    Microsoft Dynamics NAV
    —————————

    A call to System.Data.SqlClient.SqlCommand.ExecuteNonQuery failed with this message: The wait operation timed out
    —————————
    OK
    —————————

    Note:
    we already set the Query Execution property value to zero under the below path SSMS->Tools->Option->Sql

    Give the suggestion on the same.

    Thanks in advance

    Mani

    • Hey Mani,

      Is your Query executing fine directly from SQL??

      The Credentials must be correct and should be written the same way, Some times just because of wrong credentials you may end up with this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s