How to fix System.Data.SqlClient.SqlException: Login failed for user

shade1337 picture shade1337 · May 20, 2018 · Viewed 15k times · Source

When I run it I get this:

Error Screenshot

I enabled Windows authentication in IIS, SQL Server, and also added the authentication method in web.config:

<system.web>
  <authentication mode="Windows"/>
</system.web>

(I am literally out of ideas...)

As you may see, the DataConnection is running:

DataConnection Screenshot

The connection string from web.config:

<connectionStrings>
    <clear/>
    <add name="cafeaconnection" 
         connectionString="Data source=LENOVO-PC\SQLEXPRESS; Initial catalog=tipuridecafeaDB; user id=user; password=password; persist security info=True;" 
         providerName="System.Data.SqlClient" />
    <add name="ConnectionString" 
         connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\tipuridecafeaDB.mdf;Integrated Security=True" 
         providerName="System.Data.SqlClient"/>
</connectionStrings>

Error:

[SqlException (0x80131904): Login failed for user 'Shade'.]

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) +907
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +334
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, TaskCompletionSource
1 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, TaskCompletionSource
1 retry, DbConnectionOptions userOptions) +21
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) +90
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
1 retry) +443
System.Data.SqlClient.SqlConnection.Open() +96
YourCoffeeShop.App_Code.ConnectionClass.GetCafeaByType(String cafeaType) in D:\YCS\YourCoffeeShop\YourCoffeeShop\App_Code\ConnectionClass.cs:29
YourCoffeeShop.Pages.Cafea.FillPage() in D:\YCS\YourCoffeeShop\YourCoffeeShop\Pages\Cafea.aspx.cs:26
YourCoffeeShop.Pages.Cafea.Page_Load(Object sender, EventArgs e) in D:\YCS\YourCoffeeShop\YourCoffeeShop\Pages\Cafea.aspx.cs:17
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

Answer