为什么会出现这种情况,是因为web.config的数据连接设置成了这个样子: <add name="DbContext" connectionString="Data Source=localhost;Initial Catalog=CMS;Integrated Security=True;Max Pool Size=512;Min Pool Size=5;Connection Lifetime=15;connect timeout = 15;" providerName="System.Data.SqlClient" />
这里设置了integrated security=True ,集成安全模式为真。在这种情况下要求网站程序池账号与sqlserver运行使用的账号一致。我的应用程序池账号: 
我的sqlserver账号: 
明显不同·。这里可以把应用程序池账号设置为network service,sqlserver的运行账号也设置为network service,就可以避免此错误。这是第一种解决办法。也是网上最多的一种解决办法。 还有另外一种解决办法,这种网上少。就是更改web.config的连接串。去掉集成模式。改成此种: <add name="DbContext" connectionString="Data Source=localhost;Initial Catalog=CMS;User ID=sa assword=123456;Max Pool Size=512;Min Pool Size=5;Connection Lifetime=15;connect timeout = 15;" providerName="System.Data.SqlClient" /> |