Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

permission denied querying sharepoint database

Status
Not open for further replies.

theprowler

Programmer
Mar 25, 2005
29
IT
Hi all,
i've made a web part that has to make a select into sharepoint database but i get a permission denied error when i try to do that operation.

My current trust level is set to Medium Trust.

In mine web part i make this assumption:

if user.isWebAdmin //only an administrator can do this...
{
// do the selection
}

Thanks in advance!

Max
 
Web administrator also needs the rights to the database... This does not has to be the case as the error shows.
Also try full trust in your web.config incase a database connection needs this trustlvl (or deploy in the GAC).

But the most important thing is why? are you executing queries directly agains the database this is not supported and there is almost always a way through the object model!

BTW you Could also try this assumption SPWeb.CurrentUser.isSiteAdmin - he created the original database so it should work for him i guesse..

Greetings Paul
 
Yes i'm executing a query directly on Sharepoint database...

i execute this query:

select leafName, TimeLastModified, Title, as DirName from Docs inner join Webs on Webs.Id = Docs.WebId where doclibrowid is not null and timeLastModified >= 13/05/2000 + " and webs.fullUrl = <URL>;

It has to return to me latest documents inserted after a selected date in mine web part. Obviously ALL documents in ALL subsites of mine site Collection inserted after that date.

how can i do this using object model?
how can an administrator obtain the rights to perform selections on Sharepoint Database?

Thanks in advance,
Max
 
this is the error i got:

SELECT permission denied on object 'Docs', database 'myDatabase', owner 'dbOwner'.

This selection was made by an administrator.


 
Well as for the accesing the object model i have made an example that is a rough setup for what u want... (no layout and i skipped all root folders that makes it simpler :p)

Code:
string j = "";
private string LoopSites (SPWeb web, DateTime time)
{
   foreach(SPWeb x in web.GetSubwebsForCurrentUser)
   {
      j += GetLatestDocs(x);
      if(x.GetSubwebsForCurrentUser().Count > 0)
      {
         LoopSites(x, time);
      }
   }
   return j;
}

string k = "";
private string GetLatestDocs(SPWeb x, DateTime time)
{
   foreach(SPList y in x.Lists)
   {
     if (y.BaseType == SPBaseType.DocumentLibrary)
     {
         if (y.LastItemModifiedDate >= time)
         {
            k += LoopFilesInFolders(y.RootFolder, time);
         }
      }
    }
    return k;
}
        
string l = "";
private string LoopFilesInFolders(SPFolder folder, DateTime time)
{
     foreach (SPFile file in folder.Files)
     {
        if (file.TimeCreated >= time)
        {
           l += file.Name + file.Url + "<br>";
        }
     }
     if(folder.SubFolders.Count > 0)
     {
        foreach (SPFolder myFolder in folder.SubFolders)
        {
            l += LoopFilesInFolders(myFolder, time);
        }
     }
     return l;
}

protected override void RenderWebPart(HtmlTextWriter output)
{    
    DateTime time = new DateTime(2005,6,3);
    SPWeb Website = SPControl.GetContextWeb(Context);
    output.Write(LoopSites(Website, time));
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top