Following the peace treaty with the Liao in 1005 and the Xi Xia in 1006, the Song passively watched the Tanguts of Xi Xia grow in power. It wasn't until 1038 that the relations took a nosedive, when Li Yuanho declared himself Emperor of Great Xia. The Song were enraged by such a brazen move from a western barbarian state who they considered their suzerain and put a ransom on Yuanho's head. Here is an interesting analysis from the book:
Both the Song and the Xi Xia were the weaker powers in the triangular relationships with the Liao. Balance-of-power logic suggests that both states should ally against the stronger Liao. This did not happen, however, mainly because the Confucian culture of hierarchy impeded rational policymaking. The Song court saw Xi Xia independence as rebellion of a vassal state and refused to recognize it, let along making it an ally. Had the Song made an alliance with the Tanguts, China’s security environment might have substantially improved. But the cultural legacy of Confucian hierarchy made the alliance unthinkable for Song officials. In this case, cultural variable supplements structural realism by explaining behaviors contrary to structural logic.
Unfortunately for the Song, their military adventures against the Xi Xia were a failure. The Liao took advantage of Song's military setbacks and applied diplomatic pressure which resulted in a new treaty of 1042 whereby the Song agreed to increase their payments to the Liao from 100k taels of silver to 200k, and from 200k bolts of silk to 300k in exchange for peace with the Xi Xia. It is interesting to note that both the Song and the Liao treated the Xi Xia as their vassal.
“Ever since Yuanhao rebelled, we have dispatched several contingents of troops, yet without success. Today, our border defense outlays totaled 10 million units. More than 100,000 people have been killed since the war started. Thus, since antiquity, people discussing border affairs have invariably agreed that peace with the barbarians was beneficial, war harmful.” The Song emperor was pleased with his peace
proposal: “This is exactly what I have in mind."
However, this peace was not to last. At one point in the 1060s, the Song raised a staggering 1.25 million troops, causing severe fiscal crises and internal rebellions. In 1069, an official estimated that 83 percent of national income was spent on army maintenance. Emperor Shenzong who ascended the throne in 1067 was determined to wipe away generations of shame and redefine the political map through conquest and expansion. He appointed Wang Anshi as chief councilor. Wang Anshi was a practitioner of realpolitk:
“To achieve victory over the barbarians [Liao and Xi Xia],” he said in a discussion with Emperor Shenzong in 1071, “we only need to develop our domestic statecraft during leisure times. Make our generals and officials competent, our treasury plenty, and our military strong.” In another discussion with the emperor, Wang summarized his intent: “After our treasury is abundant, we can use force.” Responding to the Confucian pacifism argument that virtue should be emphasized over force, he argued that virtue (de) and force (li) must go hand in hand. A virtuous ruler would still have to cater to the barbarians if he was militarily inferior, as attested by the many examples in Chinese history. For Wang, weakness would invite aggression; strength would cause security. Enriching the state would substantially improve the livelihood of the people and make the state strong. However, his comment that “if we are capable of using force, we need not worry about finding a good reason to use it” raised many eyebrows among Confucian-minded officials. Wang was criticized for being anti-Confucian, and some of his policies were often described as Legalist. But Wang’s Confucian credential was strong. As F. W. Mote points out, “His political thought, while incorporating some elements of what we today could call a ‘managed economy,’ was entirely Confucian in its conceptual foundations and in its ideals.”
After dismissing the Wang Anshi in 1076, the emperor shifted the reform focus from "enriching the state" to "strengthening the military". The preparations for war started as early as 1077, by stockpiling weapons in the prefectures bordering the Xi Xia. However, there was opposition to such an aggressive strategy within the court.
In 1078, Zhang Fangping submitted a memorial (composed by the great literary writer Su Shi) forcefully making the case against war. Because war was a dangerous business, it should be resorted to only when there were no other alternatives. Zhang referred to several historical precedents in which excessive use of force led to the demise of dynasties. “Those who like to use force will face demise,” cautioned Zhang. The emperor, though apparently moved, was determined to use force and refused to follow Zhang’s plea for restraint
The Chinese plan was to attack the weaker Xi Xia and then turn its attention to the Liao. The Song assembled an army 300,000 men strong, which when combined with the porters totalled more than 600,000. The Xi-Xia used their strategic depth and adopted a scorched earth strategy. Out of food and starved, the Song army was forced to retreat suffering huge casualties. The Song did capture a few prefectures along the way and were determined to launch a second invasion. But before they could act, the Xi Xia launched a counter attack of some 300,000 soldiers and decimated the Chinese at Yongle. "On hearing the news of the devastating defeat, the Chinese emperor broke in tears and refused to eat."