/// <summary> /// Comment /// SQL+ Routine: .HelloWorld - Authored by Author /// </summary> public HelloWorldOutput HelloWorld(IHelloWorldInput input, bool bypassValidation = false) { if (!bypassValidation) { if (!input.IsValid()) { throw new ArgumentException("HelloWorldInput fails validation - use the HelloWorldInput.IsValid() method prior to passing the input argument to the HelloWorld method.", "input"); } } HelloWorldOutput output = new HelloWorldOutput(); if (sqlConnection != null) { using (SqlCommand cmd = GetHelloWorldCommand(sqlConnection, input)) { cmd.Transaction = sqlTransaction; HelloWorldCommand(cmd, output); } return(output); } for (int idx = 0; idx <= retryOptions.RetryIntervals.Count; idx++) { if (idx > 0) { System.Threading.Thread.Sleep(retryOptions.RetryIntervals[idx - 1]); } try { using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlCommand cmd = GetHelloWorldCommand(cnn, input)) { cnn.Open(); HelloWorldCommand(cmd, output); cnn.Close(); } break; } catch (SqlException sqlException) { bool throwException = true; if (retryOptions.TransientErrorNumbers.Contains(sqlException.Number)) { throwException = (idx == retryOptions.RetryIntervals.Count); if (retryOptions.Logger != null) { retryOptions.Logger.Log(sqlException); } } if (throwException) { throw; } } } return(output); }
/// <summary> /// Builds the command object for HelloWorld method. /// </summary> /// <param name="cnn">The connection that will execute the procedure.</param> /// <param name="input">HelloWorldInput instance for loading parameter values.</param> /// <returns>SqlCommand ready for execution.</returns> private SqlCommand GetHelloWorldCommand(SqlConnection cnn, IHelloWorldInput input) { SqlCommand result = new SqlCommand() { CommandType = CommandType.Text, CommandText = @" SELECT CONCAT('Hello ', @Name) AS WelcomMessage; IF @@ROWCOUNT = 0 BEGIN SET @ReturnValue=0; END; ELSE BEGIN SET @ReturnValue = 1; END;", Connection = cnn }; result.Parameters.Add(new SqlParameter() { ParameterName = "@Name", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.VarChar, Size = 32, Value = input.Name }); result.Parameters.Add(new SqlParameter() { ParameterName = "@ReturnValue", Direction = ParameterDirection.Output, SqlDbType = SqlDbType.Int, Value = DBNull.Value }); return(result); }