我刚刚将 Blazor CRUD 示例发布到本地服务器。网站运行良好,但当我转到获取数据页面时出现 HTTP 错误 500。当我在 Visual Studio 上运行时一切正常,但在 IIS 服务器上运行。我在上下文文件中有连接字符串。我还在应用程序池设置页面上编辑了连接字符串,但仍然无法正常工作。
这是我在上下文文件中使用的代码段:
optionsBuilder.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=master;Trusted_Connection=True;");
The answer is that there are two different LocalDB instances here. Unlike SQL Server Express instances, which are running as Windows services, LocalDB instances are running as user processes. When different Windows users are connecting to LocalDB, they will end up with different LocalDB processes started for each of them. When we connect to (localdb)\v11.0 from Visual Studio, a LocalDB instance is started for us and runs as our Windows account. But when Web Application, running in IIS as ApplicationPoolIdentity, is connecting to LocalDB, another LocalDB instance is started for it and is running as ApplicationPoolIdentity! In effect, even though both Visual Studio and Web Application are using the same LocalDB connection string, they are connecting to different LocalDB instances. Obviously the database created from Visual Studio on our LocalDB instance will not be available in Web Application's LocalDB instance.
简单的修复是使用 SQL Server Express 而不是 LocalDB
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句