Stack Overflow Asked by S_K on November 22, 2021
It was a problem with one of the packages. The Microsoft.Owin.Host.SystemWeb in venter code hereersion 4.1.0 and Microsoft.AspNet.WebPages.WebData 3.2.7
I have this code:
if (User.IsInRole("CanManageUsers"))
{
return RedirectToAction("Index", "Account");
}
Which throws the following error:
System.Web.HttpException: ‘Unable to connect to SQL Server database’
Now I can not figure out why because prior to that I’m successfully connecting to the same database and I fail to understand why in this particular case it fails.
Is there someplace where you configure the database that the User
class connects to?
I tried looking in the documentation but couldn’t find anything on this issue.
Thanks in advance
The Stack Trace:
[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: 26 - Error Locating Server/Instance Specified)]
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, SqlAuthenticationProviderManager sqlAuthProviderManager) +947
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +6040447
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +531
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +156
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +22
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +92
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +219
System.Data.SqlClient.SqlConnection.Open() +101
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +78
[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +131
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +92
System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +30
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +410
Add this entry to your webconfig:
<system.webServer>
<modules>
<remove name="RoleManager" />
</modules>
</system.webServer>
Credit to the original poster of this answer here.
Answered by TheLeb on November 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP