views:

115

answers:

2

Hi, I building a console app that runs under a normal user account to access sharepoint lists programmatically. In order to access Sharepoint objects the console application impersonates the user under the context of which the Sharepoint is running. The impersonation is successful but when I try to access any share point SPWeb objects the following error is given as follows spWeb.ID = 'spWeb.ID' threw an exception of type 'System.Data.SqlClient.SqlException' base {System.Data.Common.DbException} = {"Cannot open database \"WSS_Content_92\" requested by the login. The login failed.\r\nLogin failed for user 'DOM\USER'."}

Doesnt the imepersonation should have allowed to access to the underlying database and also do i need to explicitly grant access to the current user to give access to sharepoint lists etc.

Thanks in advance

A: 

In a console or windows app when accessing the object model - when you are impersonating the user then the database connection will be made under the users account credentials - so in effect you will have to give each of your users fairly high level permissions to access the database (or better make them a member of a group that has these permissions).

http://technet.microsoft.com/en-us/library/cc721638(office.12).aspx

This is different to the web app where the account used is the AppDomain account of the IIS site.

However - this is a very non-standard setup and is fraught with security risks - do you really want to give your users permission to access that database directly?

Instead can I suggest that you look again at your design - what are you trying to achieve?

Ryan
How does the web application manage to use the credentials of NETWORK SERVICE even if the application pool runs under the context of another account.
nitroxn
Erm - it doesn't.
Ryan
A: 

Running the console application in the context of the same user as the application pool did the trick. So the solution would be to use the runas command.

nitroxn
Well yes, it would. As would giving the account that your running the console app under db access. Its still very unclear what you're trying to achieve here?
Ryan
migrate the data from Sharepoint to another DB, does it make sense now??
nitroxn
Why do you need to access SharePoint using the users credentials?
Ryan