Page view counter

Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

Last post 08-02-2007 1:01 AM by oneBottonSally. 6 replies.

Sort Posts:

  • Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

    07-27-2005, 1:44 PM
    • Loading...
    • MEight
    • Joined on 07-27-2005, 5:23 PM
    • Posts 48
    • Points 71

    Been looking through the forums for a solution to this problem.

    I already tried granting access through statements such as:

    exec sp_grantloginaccess N1'machineName\ASPNET'

    But they don't seem to work.. i vaguely remember seeing somewhere a DOS command line statement that grants access to the ASPNET_WP and that fixed my problem before on another computer.. but this is a new computer and i forgot to write down the command.

    Can anyone help explain and propose a solution to my problem. Many thanxs.

  • Re: Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

    07-27-2005, 2:34 PM
    • Loading...
    • DarrellNorton
    • Joined on 04-04-2003, 3:49 PM
    • VA, USA
    • Posts 6,114
    • Points 48,247
    • Moderator
      TrustedFriends-MVPs
    osql -E -S InstanceName -C -Q "sp_grantlogin 'computer\ASPNET'"
    osql -E -S InstanceName -d database -Q "sp_grantdbaccess 'computer\ASPNET'"
    osql -E -S InstanceName -d database -Q "sp_addrolemember 'db_owner', 'computer\ASPNET'"InstanceName -C -Q "sp_grantlogin 'computer\ASPNET'"

    InstanceName is optional if you only installed the default instance.
    Darrell Norton, MVP
    Darrell Norton's Blog


    Please mark this post as answered if it helped you!
  • Re: Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

    07-27-2005, 2:35 PM
    • Loading...
    • tmorton
    • Joined on 08-06-2002, 5:37 PM
    • SE Pennsylvania, USA
    • Posts 6,475
    • Points 39,221
    • ASPInsiders
      Moderator
    You need to grant login permissions to the ASPNET account as well as database permissions.  Do you have Enterprise Manager?  This would help you to set permissions using a GUI tool.  Assuming you do not, then you could use the osql commandline utility.  I am also further assuming this is a local instance of SQL Server.

    Using osql, from the command prompt, this will connect you to your instance of SQL Server and put you into an interactive mode with osql:
    osql -E -S (local)

    Now you can enter the commands in the interactive mode:
    1>EXEC sp_grantlogin 'machineName\ASPNET'  
    2>GO

    1>USE yourDatabase  
    2>GO

    1>EXEC sp_grantdbaccess 'machineName\ASPNET'  
    2>GO
    1>EXIT



    Edit: sorry, didn't see Darrell's post :-)
    Terri Morton
    Engagement Manager, Neudesic
  • Re: Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

    07-28-2005, 4:26 PM
    • Loading...
    • DarrellNorton
    • Joined on 04-04-2003, 3:49 PM
    • VA, USA
    • Posts 6,114
    • Points 48,247
    • Moderator
      TrustedFriends-MVPs
    That just shows there's more than one way to do it!  Smile [:)]
    Darrell Norton, MVP
    Darrell Norton's Blog


    Please mark this post as answered if it helped you!
  • Re: Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

    07-29-2005, 10:40 AM
    • Loading...
    • MEight
    • Joined on 07-27-2005, 5:23 PM
    • Posts 48
    • Points 71
    Thanxs '%orton'

    I went with tmorton's instructions because it looked easier and more straightforward. I enabled me to get my app running after a few minor adjustments. I described what I did below but don't fully understand why it worked. Could you please help clarify? 

    I was able to grantlogin to 'machineName\ASPNET', however, got an error stating that permissions already existed for 'machineName\ASPNET' when I tried to grantdbaccess. I do have EnterpriseManager and went into the Users of the database I needed to use. I deleted the 'machineName\ASPNET' from that list. Then ran the sp_grantdbaccess 'machineName\ASPNET' again. This time succeeding. Thus my application has permissions to run. But when I went back ino the database/users, I didn't see 'machineName\ASPNET' in the User list. Why is that?

    Where can I look to see the results of executing the sp_grantlogin & sp_grantdbaccess? Shouldn't there be a list for that somewhere?

    And just to make sure that I understand what is happening. The sp_grantlogin simply gives the user 'machineName\ASPNET' permission to login into the SQLServer (1st level). Then sp_grantdbacess gives the user 'machineName\ASPNET' permission to access the specified database (from the use yourDatabase)

    Thanxs again!!!
  • Re: Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

    09-11-2005, 12:32 PM
    Answer
    • Loading...
    • tmorton
    • Joined on 08-06-2002, 5:37 PM
    • SE Pennsylvania, USA
    • Posts 6,475
    • Points 39,221
    • ASPInsiders
      Moderator
    After referring someone else to this post I realized that I never answered your questions.  I am sorry!

    MEight:
    Thanxs '%orton'
    I was able to grantlogin to 'machineName\ASPNET', however, got an error stating that permissions already existed for 'machineName\ASPNET' when I tried to grantdbaccess.

    Then you really didn't need to do anything further with *that* command. 

    MEight:

     I do have EnterpriseManager<snip>
    But when I went back ino the database/users, I didn't see 'machineName\ASPNET' in the User list. Why is that?

    Enterprise Manager is not good about refreshing data.  Either close Enterprise Manager completely and reopen it, or start at your server right-clicking and choosing Refresh on each node all of the way down until you get to the node for the data you are concerned with. 

    MEight:

    Where can I look to see the results of executing the sp_grantlogin & sp_grantdbaccess? Shouldn't there be a list for that somewhere?

    You can see this in Enterprise Manager (after forcing the data to refresh), or you can execute the sp_helplogins system stored procedure from Query Analyzer (or the osql commandline utility):
    EXEC sp_helplogins
    MEight:

    And just to make sure that I understand what is happening. The sp_grantlogin simply gives the user 'machineName\ASPNET' permission to login into the SQLServer (1st level). Then sp_grantdbacess gives the user 'machineName\ASPNET' permission to access the specified database (from the use yourDatabase)

    Yes, you've got it!  You can read up on what MSDN has to say about sp_grantlogin and sp_grantdbaccess for more information.

    If you haven't done so already, you should install SQL Server 2000 Books Online.  This is a great free SQL Server reference.




    Terri Morton
    Engagement Manager, Neudesic
  • Re: Cannot open database requested in login 'dbName'. Login fails. Login failed for user 'machineName\ASPNET'

    08-02-2007, 1:01 AM
    • Loading...
    • oneBottonSally
    • Joined on 08-02-2007, 12:53 AM
    • Posts 1
    • Points 2

    i can not do anything with sql. This is what i got :

    -------------------------------------------------------------------------------------------

    C:\Users\User>osql -E -S
    [SQL Native Client]VIA Provider: The specified module could not be found.
    [SQL Native Client]Login timeout expired
    [SQL Native Client]An error has occurred while establishing a connection to
    the server. When connecting to SQL Server 2005, this failure may be caused by
    the fact that under the default settings SQL Server does not allow remote
    connections.

    ------------------------------------------------------------------------------------------

    also, i cant create database directly from SQL Server Management Studio Express!

    the error is The permission denied in database 'master'. What should i do?

Page 1 of 1 (7 items)