On the hearing of such application, and when the application is by an executor or administrator with the will annexed, that no power is given by the will for that purpose, the court may direct the sale of all, or such portion of the real estate as may be necessary to pay the debts; and such sale may be had on such credit as the court may direct, not exceeding two years.