Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an issue with my login. I currently have a website up and it runs fine. In IIS 6.0 I added a virtual directory to the current website for the web app that I made in VS2010. It is an ASP.NET app in C#. When I publish the web app to the server name COCWEB then add it to IIS as a virtual directory, everything goes well so far. I can see the login page of the web app. When I try to login as a user I get an error:

C#
Login failed for user 'SACS-COC\COCWEB$'.

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: Login failed for user 'SACS-COC\COCWEB$'.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[SqlException (0x80131904): Login failed for user 'SACS-COC\COCWEB$'.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5063578
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   Login.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator.SACS-COC\my documents\visual studio 2010\Projects\SACSCOCLogin1.1\SACSCOCLogin1.1\Login.aspx.cs:23
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563


What does this mean? When I did it in IIS7 on my local computer everything worked, so far. Is there a way to correct this issue? Please help. Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Sep-13 13:02pm    
Not working on CodeProject!

Indeed, how do your think just the exception stack trace can be useful without the code sample?

—SA
Computer Wiz99 26-Sep-13 13:05pm    
Ok. What which code will you need? The login?
Sergey Alexandrovich Kryukov 26-Sep-13 13:10pm    
No, I won't need any code. You do, if you want help. :-)
You provide some code sample and the exception information obtained with same exact sample. Just look by yourself.
—SA

1 solution

What Sergey is saying is that this is very easily "solved", let's analyze this:

You are getting a "Login failed for user 'SACS-COC\COCWEB$'"

Ok, so some kind of security problem for that user. Now, lets look at the stack trace like the error tells us to, usually the first line gives us what we need:

C#
[SqlException (0x80131904): Login failed for user 'SACS-COC\COCWEB$'.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5063578


Ahh! There it is! You are getting an SqlException. SqlExceptions come from the SQL server. So combine that with what we already know (login failed) and the problem is that:

You need to add the user SSACS-COC\COCWEB$ to the users for the SQL database you are trying to use.

If you look a little further down in the stack trace, the database information for the database you are connecting to is somewhere around this line and file:

C#
Login.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator.SACS-COC\my documents\visual studio 2010\Projects\SACSCOCLogin1.1\SACSCOCLogin1.1\Login.aspx.cs:23


Login.aspx line 23
 
Share this answer
 
Comments
Computer Wiz99 26-Sep-13 14:15pm    
Ron Beyer, Thanks for the help. Ok, I am following you where you said about the Login.aspx line 23.

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();

What is wrong with my connection?
Ron Beyer 26-Sep-13 14:18pm    
Nothing, the user is not allowed to log into the database. You have to add the user SACS-COC\COCWEB$ to the SQL database that you are connecting to. I pointed that line out because it shows where you use the database. The connection succeeds, but the user is not allowed to access it so you have to add that user to the SQL server in the SQL Server Management console.

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