Login failed for user "DOMAIN\USER" when connecting to DB in entity framework - asp.net

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.

Related

Kentico not reading updated SQL Server servername, username or password

Kentico CMS is hosted as Azure app service. Had to change admin password for our Azure SQL Server. After updating the password in the Kentico root web.config's connection string, Kentico is still complaining with this error message
SQL Connection Error The application could not connect to the
database, please check the connection string in the web.config file
and SQL server availability.
Original error: Login failed for user 'myadminusername'
Note that there is no way I can clear Kentico cache because I cannot access the portal at all. And there is no IIS since this is an Azure app service. I have tried restarting the app service several times and no luck.
Strangely changing username or server address in web.config has no change in the error message. The same old username is displayed in the error message.
I have no issues using the connection string values in SSMS or a different application. Both work with new password.
There are 2 places to change this username and password:
web.config
Azure Application settings
By default, the application settings override the web.config settings. So you can change your password all day long in the web.config and as long as your Azure application settings remain unchanged, your website will never see those updates. I suggest checking in the Azure portal under the applications settings/configuration and see if there is a CMSConnectionString in the settings. If so, update the credentials there.

SqlException "Invalid User Account" thrown by application

I've developed a website which connects to a SQL Server 2012 instance. This works fine in my development environment. However, when trying to deploy to a production environment, the page returns the following error:
Server Error in "/theapp" Application.
Invalid User Account
Description: an unhandled exception occured 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: Invalid User Account
screen shot of stack trace
I am struggling to find any documentation regarding this on the Internet; is there anyone who might know where I can start looking for a resolution?
Thanks kindly!
Update (4/7/2016 # 3:18pm): The service account is a domain account which has correct permissions on the database. In addition, the same account is used by another website to connect to the same database, and this works fine.
Update (5/7/2016 # 10:16am): The only thing I can think of is something to do with the usage of LINQ to SQL queries within the application. Does this sound like a possible cause?
As the error says, the credentials you are using to connect to sql server are incorrect.
Make sure you are using correct credential viz. user name and password in your connection string. You can check it by logging on to sql server instance from these credentials.
If you are using integrated security, i.e. windows authentication, verify if the user have given permission on sql.
When you pass Windows authentication through a website, the identity of your app pool is the user credentials that are supplied. Be sure your app pool for the site is set to use the same user as you expect in the identity of the app pool. Also, be sure integrated security is set to SSPI, not true, in the connection string.

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.

SSISDB ASP.NET "Login failed for user 'DOMAIN\PCNAME$'"

I am using Microsoft.SqlServer.Management.IntegrationServices in an ASP.NET web form to access an SSIS project in SSISDB. Testing locally on my own PC I am able to access the package from the test server and it runs fine.
My issue comes up when I try to run the site from the test server. The same test server hosts the site with IIS 7 and hosts the Sql Server database which stores the package with Integration Services. So like I said, the package is hosted on the server and when I run the site locally on my PC, all works fine.
When I run the site on test and try to access the package I get:
System.Data.SqlClient.SqlException (0x80131904): Login failed for user '[DOMAIN]\[PCNAME]$'.
I am using integrated security in my connection string:
SqlConnection connection = new SqlConnection(#"Data Source=[Test_Server];Initial Catalog=master;Integrated Security=True;");
IntegrationServices integrationServices = new IntegrationServices(connection);
My error comes up here when trying to connect.
I've tried adding '[DOMAIN]\[PCNAME]$' as a Sql login using Windows authentication with every permission I can think of. User mapping for database SSISDB has accessadmin, datareader, datawriter, owner, public, and ssis admin. I know not all of these should be needed, but I'm trying everything.
I went to SSISDB under databases, and gave the login permission to Connect, Execute, and Select.
Under Integration Services Catalogs I gave my folder, under SSISDB catalog, permission for the my Windows User ('[DOMAIN]\[PCNAME]$') login to Read, Execute Objects, and Read Objects.
I gave the SSISDataTransfer project permission for the Windows User to Read, Modify, and Execute.
I'm out of ideas and figure it's probably some IIS issue. It has Windows Authentication installed and set.
Anyone have any ideas? I've found posts about how to get the code to work, but nothing on connection specifics. Thanks!
i have had similar problem recently and i have worked with SSIS packages being used with web applications too. in my opinion you should use a custom user account to be used as your app pool account. and you will have to add this account to your database server. when running an app pool as local system or network service, the account being used for connection to a remote database server will be "DomainName\MachineName$" which will be different for every machine which tries to connect to your sql server. so instead of adding all these user names in sql, you will be better off using a custom user account.
Secondly looks like your web application does not run on the same machine as your sql server which i think will not work because you can invoke SSIS package from the same server only.
Another thing to try is to add a credential to sql server - in Security - Credentials in SQL Server management studio. This credential would be the authenitcated user that you are running it successfully under. Then in your SSIS package, in SQL Server agent, go into the job step and in the "Run As"drop down, select the new credential for your user that you created.

Login failed for user 'IIS APPPOOL\myAppPool

I having the following error message:
Cannot open database "SmallBakery" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\MyAppPool'
How can correct this? I am using windows 7 Enterprise Edition and Sql server 2012.
If you don't change, each app pool has it's own identity. In your case, just add a new user to your database SmallBakery with the name IIS APPPOOL\MyAppPool using SQL Management Studio. You find the users list in the "Security/Users" subnode of your database. This should look something like that:
For testing, let the user be member of the db_owner role. If that works, remove this role and just let it be member of db_datareader and db_datawriter.
This way, each app pool (perhaps each website, if they all use their own app pool) only has access to the corresponding database.
It depends on how you want to authenticate in your app. Are you trying to use impersonation in your app?
What's happening right now is the identity of your app pool in IIS is getting passed when trying to access the database. You can change the identity of your app pool to be something that has access to the database or you could change your connection string to use a specific login instead of integrated security.
Check this post out. Your problem sounds similar to one I was running into, with the same exact error message.
http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-2-instance-ownership.aspx
Like others said so far you need to take your app pool system user (IIS AppPool\myapppool) and add it as database user for that database with appropriate permissions.
Note that this will work just find on your IIS/Server but if you plan on migrating application to a different IIS/Sql server it will require changes in both SQL Server and IIS. I’d suggest you also consider sql server authentication – it may be more convenient for your specific case.
In my case these steps lead me to successfully handle this error.Hope it will help you also

Resources