--------------------------- Microsoft Dynamics NAV --------------------------- This message is for C/AL programmers:The call to member Open failed. Microsoft OLE DB Provider for SQL Server returned the following message:Connection failure --------------------------- OK ---------------------------2.
--------------------------- Microsoft Dynamics NAV --------------------------- Your connection to the ABC server is no longer responding. This is probably because of one of the following reasons:* The server has been shut down, either manually or as a result of an error.* Your session has been killed by an administrator.* A network failure has occurred.* A hardware failure has occurred on the server computer or on your computer.Contact your system manager if you need assistance. --------------------------- OK ---------------------------
Name DataType Subtype Length lADOConnection Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Connection lADOCommand Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Command lADOParameter Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Parameter lADORecordSet2 Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset lVarActiveConnection Variant lrecILSSetup Record ILS Setup sResult Text 250 Decrypt(EncryptedValue : Text[250];Direction : Text[30]) : Text[250] sResult := ''; IF ISCLEAR(lADOConnection) THEN IF NOT CREATE(lADOConnection) THEN ERROR('Cannot create ADO Connection to Database. Contact IT.'); lrecILSSetup.GET; WITH lrecILSSetup DO lADOConnection.ConnectionString(STRSUBSTNO(ConnectStr,Provider,"Status Data Source","Status Catalog",sUserID,Password)); lADOConnection.Open; IF ISCLEAR(lADOCommand) THEN IF NOT CREATE(lADOCommand) THEN ERROR('Cannot create ADOCommand in connecting to Database. Contact IT.'); lVarActiveConnection := lADOConnection; lADOCommand.ActiveConnection := lVarActiveConnection; // CommandType 4 = adCmdStoredProc (evaluates to Stored Procedure) // http://www.devguru.com/technologies/ado/quickref/command_commandtype.html lADOCommand.CommandText := 'usp_Decrypt; lADOCommand.CommandType := 4; lADOCommand.CommandTimeout := lrecILSSetup."ADO Timeout"; // CreateParameter(Parameter,Type,Direction,Size,Value) // 200 = adVarChar (string), 135 = adDBTimeStamp (YYYYMMDDHHMMSS datetime) // http://www.devguru.com/Technologies/ado/quickref/command_createparameter.html lADOParameter := lADOCommand.CreateParameter('@value', 200, 1, 250,EncryptedValue); lADOCommand.Parameters.Append(lADOParameter); lADOParameter := lADOCommand.CreateParameter('@direction', 200, 1, 250,Direction); lADOCommand.Parameters.Append(lADOParameter); lADOCommand.Execute; //Create record set to pull return (decrypt value) IF ISCLEAR(lADORecordSet2) THEN CREATE(lADORecordSet2); lADORecordSet2.ActiveConnection := lVarActiveConnection; lADORecordSet2.Open('SET NOCOUNT ON'); lADORecordSet2.Open(lADOCommand); // <-- ERRORS THROWN HERE WHILE NOT lADORecordSet2.EOF DO BEGIN sResult := lADORecordSet2.Fields.Item('CCRESULT').Value; lADORecordSet2.MoveNext; END; lADORecordSet2.Close; lADOConnection.Close; CLEAR(lADOConnection); EXIT(sResult);
Answers
Basically, if we comment out
the Recordset opens without error and we get our result back.
I tried this because I noticed a subtle difference between my C/AL and the VB6 app our other developer threw together to test a 3rd party app calling the SP and receiving a result.
His code handled the recordset in a much simpler manner. I noticed that the C/AL examples always had: I decided to try commenting out the explicit Execute as a test and it was successful. I received back the expected results.
Any thoughts on why I had to comment out the Command.Execute to get this to work?