最近,我设法使用ASP.NET设置我的GUI和API之间的模拟(参见here)。下一个问题并不遥远:数据库访问。每当我在API中调用其他用户(例如user1
设置为管理员)而不是启动应用程序的操作时,我会收到以下错误:
System.Data.SqlClient.SqlException(0x80131904):建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供程序:SQL网络接口,错误:50 - 发生本地数据库运行时错误。无法创建自动实例。有关错误详细信息,请参阅Windows应用程序事件日志。)
使用此堆栈跟踪:
bei System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
bei System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
bei System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
bei System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
bei System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
bei System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
bei System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
bei System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
bei System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
bei System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
bei System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
bei System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
bei System.Data.SqlClient.SqlConnection.Open()
bei Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
bei Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
bei Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.Exists()
bei Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
bei Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
bei Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
bei ReconAPI.Models.ReconDbContext..ctor() in D:\projects\recon\Trunk\ReconAPI\Models\ReconDbContext.cs:Zeile 17.
bei ReconAPI.Services.BaseService..ctor() in D:\projects\recon\Trunk\ReconAPI\Services\BaseService.cs:Zeile 11.
bei ReconAPI.Services.UserService..ctor() in :Zeile 0.
bei ReconAPI.Controllers.BaseController.get_UserService() in D:\projects\recon\Trunk\ReconAPI\Controllers\BaseController.cs:Zeile 166.
bei ReconAPI.Controllers.UsersController.Read() in D:\projects\recon\Trunk\ReconAPI\Controllers\UsersController.cs:Zeile 21.
要非常清楚:如果我和“我的”用户一起尝试,一切都很完美。
我的连接字符串是
Server=(localdb)\mssqllocaldb;Database=Recon;AttachDbFilename=D:\projects\recon\Trunk\db\Recon.mdf;Integrated Security=SSPI
有些人在我之前遇到过这个错误。但是建议的解决方案不适用于我(例如防火墙)或不适用于我(例如共享实例)。
user1
连接到此实例。但我只能看到系统表。user1
具有所有权限。所以我被卡住了。需要做些什么才能允许多个用户通过GUI / API从模拟的IIS(Express)访问数据库?
如上所述here,这对于LocalDB来说根本不可能,但应该与SQL Express一起使用。也许这是要走的路?
祝你好运, 卡斯滕