System.Data.Sqlclient.Sqlexception: Login Failed for User

System.Data.SqlClient.SqlException: Login failed for user

Assuming you're intending to use Windows Authentication to impersonate the service account, you have to set up Windows Authentication in both IIS and ASP.NET.

In IIS, make sure that the Windows Authentication module is added and enabled. Also make sure your application pool is running under a domain account, not a local account.

In ASP.NET make sure the authentication mode attribute is set to "Windows"

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

How to fix System.Data.SqlClient.SqlException : Login failed for user xx\xxxx$

According to the error message, the account 'domain\account$' does not have access to the myTable database.

I suggest you could firstly use the SQL server management system's security to check he account 'domain\account$' does not have access to the (local) server's myTable database.

More details, you could refer to this answer.


Update:

As far as I know, if you want to access SQL Server Using Windows Integrated Security. You should firstly make sure your IIS server and the sql server is inside the same intranet and use the same domain.

Then I suggest you could make sure you have set the right application pool identity account which has the permission to access the sql database.

1.You should the domain account "domain\account" in sql server to make sure it has the read and write permission

2.On IIS, open Application Pool settings.For Identity option, choose "Custom Account". Enter your username domain\account) and password.

Then it will work well.

System.Data.SqlClient.SqlException: Login failed for user '' with a .NET Core 2.2 app

"KitLogContext": "Server={server};Database=DB;user Id=DBAdmin;Password=DB_Password;Trusted_Connection=True;MultipleActiveResultSets=true",

You're setting Trusted_Connection=True, but providing a User_ID and Password. These are incompatible connection string settings.

Set Trusted_Connection=False if you are using a SQL Login and Password.

Otherwise add the AppDomain identity as a login to SQL Server. If IIS is running on the SQL Server this will be the Application Pool Identity. If the SQL Server is remote this may be the Machine Account for the IIS server, eg SomeDomain\ServerName$. EG

use DB
create login [SomeDomain\ServerName$] from windows
create user [SomeDomain\ServerName$] for login [SomeDomain\ServerName$]
alter role AppUserRole add member [SomeDomain\ServerName$]

Where AppServerRole is a custom database role with the least privileges to run your application code. eg

use DB
create role AppServerRole
grant select, execute on schema::dbo to AppServerRole

System.Data.SqlClient.SqlException: 'Login failed for user 'root'

You are using SqlConnection to connect database while you should use MySqlConnection and MySqlCommand to connect and operate with MySQL Server.

Make sure database name and credentials are correct and connection string looks good.

Moreover you can try below connection string:

<add name="EmployeeAppDB" connectionString="Server=localhost; Database=employeedb; Uid=root; Pwd=root;Convert Zero Datetime=True;Connection Timeout=60;"/>

System.Data.SqlClient.SqlException: Login failed for user 'ASPHOST166\IWAM_plesk(default)'

Looks like your application runs under account which is not exist in SQL server. Thus you have login and password specified in connection string for Entity Framework, I think you need remove Integrated Security=True; from this Entity Framework connections string:

<add name="DatabaseEntities" 
connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />

UPDATE: According to your error message, user instance login flag is not supported on your version of SQL server. So remove also User Instance=True; parameter.

System.Data.SqlClient.SqlException: Login failed for user ''

Either you can put integrated security=true to login with windows credentials or add your username and password in the connectionstring, Just add a user and add the details



Related Topics



Leave a reply



Submit