Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Quote:
Cannot open database "ankur" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
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 "ankur" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.

Source Error:


Line 19: myadp.SelectCommand = new SqlCommand();
Line 20: myadp.SelectCommand.Connection = con;
Line 21: con.Open();
Line 22: myadp.SelectCommand.CommandText = "select * from user1 where user1=@un and password1=@ps";
Line 23: myadp.SelectCommand.Parameters.AddWithValue("@un", TextBox1.Text);
Posted

Your connection string has problem, you are trying to access your database from application hosting system and from that system your database is not accessible that's why you got this error.
Check you connection string make appropriate changes to connection string and also make sure that your database is accessible over your hosted system.
 
Share this answer
 
What this is telling you is that you have integrated security set in your database connection string. This means that the application will attempt to connect based on the identity of the user on the web server. Now, your website is running inside an application pool that has a user set to IIS_APPPOOL\DefaultAppPool. You either need to set your application pool to run as a secure, low privilege user in the database, or you need to change your connection string to run as a secure, low privilege named user. In either case, you must ensure that you have setup this user in the database. Good security practice dictates that you allocate the lowest possible privileges for this user both at the operating system and the database levels.
 
Share this answer
 
Comments
Shantanu sinha 8-Jan-14 6:28am    
how can i perform that
Pete O'Hanlon 8-Jan-14 6:58am    
If I were you, I would follow this link and start reading up about SQL Server and IIS best practices. https://www.google.co.uk/search?q=iis+app+pool+sql+server+security&oq=iis+app+pool+sql+server+security&aqs=chrome..69i57.9713j0j7&sourceid=chrome&espv=210&es_sm=122&ie=UTF-8#es_sm=122&espv=210&q=iis+sql+server+security+best+practices There's no easy answer for you here, I'm afraid, because the answer really depends on your company security policies - you might want to talk to your system administrators about this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900