A district attorney, or other prosecuting attorney, shall not compromise any cause or enter a nolle prosequi either before or after indictment found, without the consent of the court; and, except as provided in the last preceding section, it shall not be lawful for any court to dismiss a criminal prosecution at the cost of the defendant, but every cause must be tried unless dismissed by consent of the court.