在 IIS 数据库连接问题上托管 ASP.NET Web 应用程序

Hosting ASP.NET Web App on IIS DB connection problems

我以前使用过IIS,但我从未使用过数据库,也从未做过Web 应用程序。我执行了相同的步骤将网站放到 IIS 上,除了当我转到一个有数据库连接的页面时,一切正常。我已经尝试了很多,这就是我得到的。

A network-related or instance-specific error occurred while establishing a >connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.

Windows 应用程序事件日志:

Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.

这是 Visual Studio 内置的,我有一个 SQL Express 数据库。 我发布了我的连接字符串,非常感谢任何帮助。

我已将此添加到我的 applicationHost.config:

<add name="DefaultAppPool">
    <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />

现在我得到:

An attempt to attach an auto-named database for file |MY DB1 FILE| failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB1.mdf;Initial Catalog=aspnet-ICCAA_VIZIER-20150223043129;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="ConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB2.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>

我想通了。我将所有数据连接更改为 .\SqlExpress。这导致我犯了另一个错误:

Login failed for user ‘NT AUTHORITYNETWORK SERVICE‘

为了解决这个问题,我按照这篇文章来解决这个问题。

Login Failed For user NetworkService