A connection was successfully established with the server, An Error Occurred During The Pre-Login Handshake in ASP.NET Core 6 - c#

I have created a Scheduler Task Console Application in ASP.NET Core 6. The local environment service is working as expected, but not when it is deployed to the production server.
It worked fine when the Job was executed the first time. After that when the job is running I get the following error. The application is scheduled in JAMS Job Schedular.
Exception Details: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.), StackTrace: at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
I have added ;TrustServerCertificate=true in the connection string. Find the following connection string.
"Data Source=myTest;Initial Catalog=testDB;persist security info=True;User Id=testuser;Password=testPwd;MultipleActiveResultSets=True;TrustServerCertificate=true"
I'm having the same problem/issue.
Any idea what could be wrong?

I tried and solved the issue by adding the following to the connection string.
;MultiSubnetFailover=True;TrustServerCertificate=True
"Data Source=myTest;Initial Catalog=testDB;persist security info=True;User Id=testuser;Password=testPwd;MultipleActiveResultSets=True;MultiSubnetFailover=True;TrustServerCertificate=True"

Related

MSSQL Error 'The underlying provider failed on Open' IIS deployment

Hello i have an API webservice using entity framework runing without problem, but when i deploy it in iis in the same machine i got this execption:
Exception: The underlying provider failed on Open.Inner Exception: System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'GRUPOTOTAL99\\GTLTSISW13W10$'.\r\n en 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)\r\n en System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)\r\n en System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)\r\n en System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)\r\n en System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)\r\n en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n en System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)\r\n en System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\r\n en System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)\r\n en System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)\r\n en System.Data.SqlClient.SqlConnection.Open()\r\n en System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n en System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)\r\n en System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()\r\n en System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n en System.Data.Entity.Core.EntityClient.EntityConnection.Open()\r\nClientConnectionId:9a382a4d-6baf-47f6-8283-f9eb07d6c73d\r\nError Number:18456,State:1,Class:14","data":null,"result":0}
It says login failed, is there any options or configuration file that i can change to make it work?
Here is my connection string using windows authentication
<connectionStrings>
<add name="AutogestionEntities" connectionString="metadata=res://*/Models.EntityDB.csdl|res://*/Models.EntityDB.ssdl|res://*/Models.EntityDB.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.215\devinst01;initial catalog=Autogestion;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
You need to create a login for your API's application pool in SQL server.

Connection SQL Server 2012 via Windows service

I created a windows service for monitoring to send data (OS info, proc, ram etc) to my SQL Server database and it works fine on my computer. I already installed the service in another machine that has SQL Server and it can connect to mydatabase successfully but when the service runs it appear those error in service log.
This is my connection string
CONNECTION_STRING = "Server=*******\\SQLEXPRESS;Database=Parc_informatique; User Id=tsi;password=******;";
Also the service run as local user
2020-07-22 15:09:34.7392 - DEBUG: Starting service
2020-07-22 15:09:34.7392 - DEBUG: Callback started
2020-07-22 15:09:34.7392 - DEBUG: Starting sending Data
2020-07-22 15:09:35.1712 - ERROR: System.Data.SqlClient.SqlException (0x80131904): Échec de l'ouverture de session de l'utilisateur 'AUTORITE NT\ANONYMOUS LOGON'.
at 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)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at SignalRbus.InfoManager.SendData() in C:\Users\Rayen\source\repos\project\SignalRbus\SystemInfo.cs:line 197
at DetailService.Service1.serviceTimer_callback(Object state) in C:\Users\Rayen\source\repos\project\DetailService\Service1.cs:line 45
ClientConnectionId:a19ffe41-1f72-4e44-a883-f4eed400e93e
Error Number:18456,State:1,Class:14
ClientConnectionId :00000000-0000-0000-0000-000000000000
Error Number :-1,State :0,Class :20
I solved it by adding Integrated Security=False to the connection string like this
CONNECTION_STRING = "Server=*\SQLEXPRESS;Database=Parc_informatique; User Id=tsi;password=;Integrated Security=False;"

Login failed for user 'DESKTOP-SBFCRKL\Shaharyar Parekh'

I want to connect my asp.net web page to SQL Server 2014. My connection string is:
connectionString="Data Source=DESKTOP-SBFCRKL\SQLEXPRESS;
Initial Catalog=OnlineShop;
Integrated Security=True;"
When I run the project I get:
**> Server Error in '/onlineshoes' Application.
Cannot open database "OnlineShop" requested by the login. The login
failed. Login failed for user 'DESKTOP-SBFCRKL\Shaharyar Parekh'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open
database "OnlineShop" requested by the login. The login failed. Login
failed for user 'DESKTOP-SBFCRKL\Shaharyar Parekh'.
Source Error:
Line 781: this.Adapter.SelectCommand =
this.CommandCollection[0]; Line 782:
DS_CAT.CATEMST_SELECTDataTable dataTable = new
DS_CAT.CATEMST_SELECTDataTable(); Line 783:
this.Adapter.Fill(dataTable); Line 784: return dataTable;
Line 785: }
Source File: c:\Users\Shaharyar Parekh\AppData\Local\Temp\Temporary
ASP.NET Files\onlineshoes\11df693e\771d1f70\App_Code.rcz9orfq.2.cs
Line: 783
Stack Trace:
[SqlException (0x80131904): Cannot open database "OnlineShop"
requested by the login. The login failed. Login failed for user
'DESKTOP-SBFCRKL\Shaharyar Parekh'.]
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) +821
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo,
DbConnectionPool pool, DbConnection owningConnection,
DbConnectionOptions userOptions) +332
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool
pool, DbConnection owningObject, DbConnectionOptions options,
DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject, DbConnectionOptions userOptions, DbConnectionInternal
oldConnection) +699
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject, DbConnectionOptions userOptions, DbConnectionInternal
oldConnection) +89
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection
owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean
allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions
userOptions, DbConnectionInternal& connection) +426
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection
owningObject, TaskCompletionSource1 retry, DbConnectionOptions
userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection
owningConnection, TaskCompletionSource1 retry, DbConnectionOptions
userOptions, DbConnectionInternal oldConnection, DbConnectionInternal&
connection) +191
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection
outerConnection, DbConnectionFactory connectionFactory,
TaskCompletionSource1 retry, DbConnectionOptions userOptions) +154
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory,
TaskCompletionSource1 retry, DbConnectionOptions userOptions) +21
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1
retry) +90
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1
retry) +209 System.Data.SqlClient.SqlConnection.Open() +96
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) +120
System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32
startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior
behavior) +160 System.Data.Common.DbDataAdapter.Fill(DataTable
dataTable) +108
DS_CATTableAdapters.CATEMST_SELECTTableAdapter.select() in
c:\Users\Shaharyar Parekh\AppData\Local\Temp\Temporary ASP.NET
Files\onlineshoes\11df693e\771d1f70\App_Code.rcz9orfq.2.cs:783
KPATEL_Home.Page_Load(Object sender, EventArgs e) in
f:\Downloads\Compressed\onlineshoes\Home.aspx.cs:26
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+678**
Does anybody know how to solve this issue?
I did resolve this by Starting the SQL Server (MSSQLSERVER) service.
You can do this as below:
Open Services window (Start -> All Programs -> Windows
Administrative Tools -> Services shortcut).
Right Click on SQL Server (MSSQLSERVER).
Press Start.
Try following connection string:
connectionString="Data Source=.\SQLEXPRESS;
Initial Catalog=OnlineShop;
Integrated Security=True;"
Try this connection string
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=your-server-name; database=databaseName;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

System.Data.SqlClient.SqlException (0x80131904) with impersonation

Recently, I managed to setup the impersonation between my GUI and the API with ASP.NET (see here). The next issue was not far away: The database access. Whenever I call an action in the API with another user (e.g. user1 who is set up as an administrator) than the one who started the application, I get the following error:
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 create an automatic instance. See the Windows Application event log for error details.)
With this stack trace:
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.
To be very clear: Everything is working perfectly if I try it with "my" user.
My connection string is
Server=(localdb)\mssqllocaldb;Database=Recon;AttachDbFilename=D:\projects\recon\Trunk\db\Recon.mdf;Integrated Security=SSPI
There are some people who have encountered this error before me. But either the suggested solutions do not apply for me (e.g. firewall) or do not work for me (e.g. sharing an instance).
I've tried to connect to this instance with user1 in the MS SQL Server Management Studio. But I all I can see are the system tables.
I've checked the access privileges on the database files itself: user1 has all privileges.
So I am stuck. What needs to be done to allow multiple users to access the database via the GUI/API from an impersonated IIS (Express)?
As stated here, this is simply not possible with LocalDB but should be with SQL Express. Maybe that's the way to go?
Best regards,
Carsten

Login failed for user 'sc' even after

I am trying to run a web application but I just cannot login with a user account (sc). I keep getting
Login failed for user 'sc'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed
for user 'sc'.
I have given the user sc the following permissions
The login Status is enabled and permission to connect is also granted
My connection string -
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" executionTimeout="43200" maxRequestLength="104856" />
</system.web>
<appSettings>
<!--<add key="ConnectionString" value="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=test;Integrated Security=True" />-->
<add key="ConnectionString" value="data source=(LocalDB)\MSSQLLocalDB;UID=sc;PWD=mystrongpassword;initial catalog=test;"/>
</appSettings>
</configuration>
User Mapping
Here is my Event log -
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 7/19/2016 3:12:31 PM
Event time (UTC): 7/19/2016 9:42:31 AM
Event ID: 5512cef4f9054c2093a8899c987115be
Event sequence: 7
Event occurrence: 3
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT/Dashboard-1-131133944396956249
Trust level: Full
Application Virtual Path: /Dashboard
Application Path: C:\inetpub\wwwroot\Dashboard\
Machine name: W104QWRX52
Process information:
Process ID: 19332
Process name: w3wp.exe
Account name: IIS APPPOOL\DefaultAppPool
Exception information:
Exception type: SqlException
Exception message: Login failed for user 'sc'.
at 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)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.ApplicationBlocks.Data.SqlHelper.PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, String commandText, SqlParameter[] commandParameters, Boolean& mustCloseConnection)
at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters)
at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText)
at Helper.getProductCount() in c:\inetpub\wwwroot\Dashboard\App_Code\helper.cs:line 44
at charts_ProductCount.GenerateProductCountChart() in c:\inetpub\wwwroot\Dashboard\charts\ProductCount.ascx.cs:line 24
at charts_ProductCount.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Dashboard\charts\ProductCount.ascx.cs:line 18
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Request URL: http://localhost/Dashboard/Home.aspx
Request path: /Dashboard/Home.aspx
User host address: ::1
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\DefaultAppPool
Thread information:
Thread ID: 14
Thread account name: IIS APPPOOL\DefaultAppPool
Is impersonating: False
Stack trace: at 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)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.ApplicationBlocks.Data.SqlHelper.PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, String commandText, SqlParameter[] commandParameters, Boolean& mustCloseConnection)
at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters)
at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText)
at Helper.getProductCount() in c:\inetpub\wwwroot\Dashboard\App_Code\helper.cs:line 44
at charts_ProductCount.GenerateProductCountChart() in c:\inetpub\wwwroot\Dashboard\charts\ProductCount.ascx.cs:line 24
at charts_ProductCount.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Dashboard\charts\ProductCount.ascx.cs:line 18
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
I've been through several posts suggesting to create user/assign permission/change connection string etc but none has helped so far. Any help is appreciated.
Just running through a list of checks you can do here:
Check that the login is working correctly. So can you log into SQL Management Studio with the 'sc' user?
Check that the problem is not specific to this user. Does the connection string work with another user and only fails for the 'sc' user?
If any user fails, we can assume the issue is not with the login but in another place which could be the Code attempting to connect, Configuration for IIS, Windows firewall or SQL Server. Maybe look into the application pool or server protocol configurations.
Also, the error code is 3005 (ErrorHttpAttemptConnect) description is 'Cannot attempt a connect due to network error'. So maybe try increasing the connection timeout.
Lastly, I would say check the common connection problems online.
This may be a good start: http://social.technet.microsoft.com/wiki/contents/articles/2102.how-to-troubleshoot-connecting-to-the-sql-server-database-engine.aspx

Categories