SQLEXPRESS user login error - asp.net

I'm trying to fire a web application from my local pc and it throws the error "Login failed for user DOMAIN\USER" (please note that I didn't type my actual values for the DOMAIN and USER in the above error).
I connect to SQLEXPRESS
Database is added through MSSMS and a new user is added to the DB with the values from connection string.
Changed authentication to SQL Server and Windows Authentication Mode but still the same error.
Changed connection string with Windows login details but still the same error

Are you intending to login using SQL authentication or Windows authentication? It sounds like you are trying to login using SQL authentication (i.e. named SQL User and password), but your connection string is indicating to use windows authentication (something like SSPI=True)
So you need to verify what login method you want to use: Windows or SQL
Then you need to post your connection string

Related

Login failed for user "DOMAIN\USER" when connecting to DB in entity framework

I have an asp.net application running in IIS using the account which has access to my database. With windows authentication, I am able to log into this account in sql server manager and other things. In my connection string, I have Integrated Security=true, and the error message I get when loading a page using this connection string references the correct user. (Not 'IIS APPPOOL\ect...' like all the other instances of this question I have found on SO). Is there something else that can cause this issue? I just dont understand why I am able to log in with the same windows account in other applications.

Login failed for user '' IIS

Im currently trying to deploy my .NET MVC Application to IIS 7.5.
There is a database connection problem that im trying to figure out. In localhost, everything seems fine, however, when I deploy my app to remote server, the app runs, without connecting to database. For example I have a VisualLeadController that has getMonthlyLeadsByYear() method that connects to database and retyrns data. When I try to execute it from brower by typing
http://staging2.landornet.com/WebLeadsVisualizer/VisualLead/getMonthlyLeadsByYear
It generates this error:
Exception Details: System.Data.SqlClient.SqlException: Login failed for user ''.
The steps that I followed:
1-Removed integrated security=True from WebConfig connection strings
2- Changed applicationpool identity from applicationPoolIdentity to local system.
Still now working... anyone has any idea?
When deploying your web app to your remote server, you will need to use a SQL connection string that contains an explicit username and password associated with a SQL account. For example,
Data Source=SERVER;Initial Catalog=DATABASENAME;User ID=SQLUSERNAME;Password=SQLUSERPASSWORD
To use this connection string, you will need to first use SQL Management Studio to create a SQL login with a username and password, and give that user access to your database. Then log out out of SQL Management Studio and log back in using that user/password to make sure that it correctly can access your database. Hopefully then your web app should be able to connect to the database.

SQL Windows Auth

I have a local test environment set up with IIS. I'm using the connection string below to connect with c# in the codebehind of an ASPX page using my windows auth. I am getting the error that [PCNAME]/ASPNET login failed. Why is the user name ASPNET attempting to login when I've specified my connection string to use my login?
user id=[UID];password=[PASS];server=[LOCALSERVER];database=db_specialOps;Trusted_Connection=yes
Trusted authentication uses the credentials of the user that is executing the process. If it is specified as yes, then the username and password in your connection string are ignored.
In this case, the ASPNET user account is the user that is running the process, so this is the account that is being used to connect to SQL Server.
Checking, another SO question addresses this issue.
When using Trusted_Connection=true and SQL Server authentication, will this effect performance?
Remove the Trusted_Connection=yes part of the connection string. It tells the sql client library to connect to the sql server, using the Windows auth, with the current process' Windows identity. In the ASP.NET case that is [PCNAME]/ASPNET. That's why you see that error message.
If you want to use sql auth, just supply username and password as you do - without the Trusted_Connection=yes part.
Connection string for Windows authentication:
connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes"
OR
connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"
No user/pass
Connection string for SQL authentication with user/pass
connectionString="Server=MyServer; Database=pubs; User Id=MyUser; password= P#ssw0rd"
providerName="System.Data.SqlClient"
Also see this question, might help you:
Connect to SQL Server using windows authentication and specific account

IIS/ASP.NET connecting to SQL Server using unknown user

Defined a SQL Server, which only user x (in the domain) is allowed to connect to and only by using windows authentication.
I am connecting to the computer using user x successfully.
I am running my website from visual studio successfully.
But when I am trying to access my website on IIS it fails because it is using a different user than x:
When my ASP.NET web site is trying to connect it fails because it is using user y.
The connection string does not specify a user and password it uses windows authentication.
where did user y came from? is it the user that IIS was installed with or log on with?
The SQL Server is not mine so I cannot add users or change the authentication method there.
Is there a way that IIS/ASP.NET to impersonate (is that the term) user x?
Do you have Integrated Security=True in your connection string?
If so it's going to try to use the anonymous/IIS_USER account to access the DB instead of what you have in your connection string.

Login failed for SQL Server user through asp.net page

I am trying to connect to SQL server through an asp.net page and I am getting this error:
Cannot open database "dbname" requested by the login. The login failed.
Login failed for user 'username'.
And when I try to login directly at SQL using the same credentials it does connect successfully. And the username and password set in the webconfig are correct.
I tried setting a new password, remove the user from the database and add it again but it doesn't work through web only through SQL.
The Database (or Initial Catalog) value in the connection string refers to a database (on the server) that doesn't exits or the login has no permissions.
When you connect using the SQL tools, it is picking up the default database (defined by the login) or you are sending a working value
Edit, after comment
The error says Cannot open database "dbname" requested by the login..
This means the database value in the asp.net generated connection string is wrong. Not much scope for ambiguity here

Resources