IIS Express 无法连接到 LocalDB
IIS Express not able to connect to LocalDB
我有一个使用 IIS Express 和 LocalDB 的示例 .NET Core 2.1 应用程序,但是每当我 运行 WebAPI 应用程序时,我都会收到以下错误:
System.Data.SqlClient.SqlException (0x80131904): 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 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.
我的连接字符串是:
"ConnectionStrings": {
"DefaultConnection": "Data Source=(localdb)\MSSQLLocalDB,1433;AttachDbFilename=C:\temp\gitprojects\TokenAuthAPI\TokenAuthAPI\TokenAuth.mdf;Integrated Security=True"
}
我最初没有 .mdf
路径或 1433 但我在网上查看后添加了这些路径,但仍然出现同样的错误。
在 Visual Studio 下 SQL Server Object Explorer 我创建了数据库并看到了它,当我 运行
命令(在命令提示符中)SQLLocalDb 信息 MSSQLLocalDB 我看到了 运行ning.
如果我右键单击并检查 SQL 服务器对象资源管理器中的数据库属性并使用该连接字符串,我会得到同样的错误:
Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TokenAuth;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
这与 IIS 权限有关吗?
您必须添加一个池
只要 AppPool 名称实际存在,现在就应该创建登录。
我是如何让它工作的:
- 在 SQL Server Management Studio 中,查找安全文件夹(与数据库、服务器对象等文件夹处于同一级别的安全文件夹...不是每个单独数据库中的安全文件夹)
- 右键单击登录和select“新登录”
- 在登录名字段中,键入 IIS APPPOOL\YourAppPoolName - 不要单击搜索
- 填写您喜欢的任何其他值(即身份验证类型、默认数据库等)
- 点击确定
或
CREATE LOGIN [IIS APPPOOL\MyAppPool] FROM WINDOWS;
CREATE USER MyAppPoolUser FOR LOGIN [IIS APPPOOL\MyAppPool];
我有一个使用 IIS Express 和 LocalDB 的示例 .NET Core 2.1 应用程序,但是每当我 运行 WebAPI 应用程序时,我都会收到以下错误:
System.Data.SqlClient.SqlException (0x80131904): 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 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.
我的连接字符串是:
"ConnectionStrings": {
"DefaultConnection": "Data Source=(localdb)\MSSQLLocalDB,1433;AttachDbFilename=C:\temp\gitprojects\TokenAuthAPI\TokenAuthAPI\TokenAuth.mdf;Integrated Security=True"
}
我最初没有 .mdf
路径或 1433 但我在网上查看后添加了这些路径,但仍然出现同样的错误。
在 Visual Studio 下 SQL Server Object Explorer 我创建了数据库并看到了它,当我 运行 命令(在命令提示符中)SQLLocalDb 信息 MSSQLLocalDB 我看到了 运行ning.
如果我右键单击并检查 SQL 服务器对象资源管理器中的数据库属性并使用该连接字符串,我会得到同样的错误:
Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TokenAuth;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
这与 IIS 权限有关吗?
您必须添加一个池 只要 AppPool 名称实际存在,现在就应该创建登录。
我是如何让它工作的:
- 在 SQL Server Management Studio 中,查找安全文件夹(与数据库、服务器对象等文件夹处于同一级别的安全文件夹...不是每个单独数据库中的安全文件夹)
- 右键单击登录和select“新登录”
- 在登录名字段中,键入 IIS APPPOOL\YourAppPoolName - 不要单击搜索
- 填写您喜欢的任何其他值(即身份验证类型、默认数据库等)
- 点击确定
或
CREATE LOGIN [IIS APPPOOL\MyAppPool] FROM WINDOWS;
CREATE USER MyAppPoolUser FOR LOGIN [IIS APPPOOL\MyAppPool];