Monday, September 15, 2008

Logon failed for user MACHINENAME/ASPNET

Some weeks back, everything was working fine with the login MYCOMPUTER/ASPNET on the SQL Express Server.

I formatted my machine recently and during 're-installation' of the operating system, I used a MACHINENAME instead of the default MYCOMPUTER.

Then, I run the aspnet_regiis command and it seems to me that the user MACHINENAME/ASPNET has been created and is also being used as login onto the database.

The client application throws the following exception:

System.Data.SqlClient.SqlException: Cannot open database "XXXDATABASEXXX.MDF" requested by the login. The login failed.
Login failed for user 'MACHINENAME\ASPNET'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
... ... ... ...
... ... ... ...

The database should now be configured to recognise this new MACHINENAME/ASPNET user.

I tried to replace the MYCOMPUTER/ASPNET user with MACHINENAME/ASPNET user in the database properties but can't find the MACHINENAME/ASPNET user in the available list of users. Any reason for that???

Anyways, instead of losing precious time finding the right way, the following SQL statement will create the user on the database and allow successful login. Just you have to make sure that the appropriate permissions are set once the user has been created.


Don't forget to change XXXDATABASEXXX and MACHINENAME to the appropriate names on your machine...


Anonymous said...


ashvin said...

The text with red would be different based on the PC name / database file name. So, here they are merely examples.