Showing posts with label statements. Show all posts
Showing posts with label statements. Show all posts

Tuesday, March 20, 2012

Cannot open database requested in login dbName. Login fails. Login failed for user machine

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.

osql -E -SInstanceName -C -Q "sp_grantlogin 'computer\ASPNET'"
osql -E -SInstanceName -ddatabase -Q "sp_grantdbaccess 'computer\ASPNET'"
osql -E -SInstanceName -ddatabase -Q "sp_addrolemember 'db_owner', 'computer\ASPNET'"InstanceName -C -Q "sp_grantlogin 'computer\ASPNET'"
InstanceName is optional if you only installed the default instance.
|||You need to grant login permissions to the ASPNET account as well asdatabase permissions. Do you have Enterprise Manager? Thiswould help you to set permissions using a GUI tool. Assuming youdo not, then you could use the osql commandline utility. I amalso further assuming this is a local instance of SQL Server.
Usingosql, from the command prompt, this will connect you to your instanceof 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 :-)
|||That just shows there's more than one way to do it! Smile [:)]
|||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!!!|||After referring someone else to this post I realized that I never answered your questions. I am sorry!

MEight wrote:

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


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

MEight wrote:


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


Enterprise Manager is not good about refreshing data. Eitherclose Enterprise Manager completely and reopen it, or start at yourserver right-clicking and choosing Refresh on each node all of the waydown until you get to the node for the data you are concernedwith.

MEight wrote:


Where can I look to see the results ofexecuting the sp_grantlogin & sp_grantdbaccess? Shouldn't there bea list for that somewhere?


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

MEight wrote:


And just to make sure that Iunderstand what is happening. The sp_grantlogin simply gives the user'machineName\ASPNET' permission to login into the SQLServer (1stlevel). 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 aboutsp_grantlogin andsp_grantdbaccess for more information.
If you haven't done so already, you should installSQL Server 2000 Books Online. This is a great free SQL Server reference.


|||

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?