Error when executing SLKStore

Topics: Developer Forum, User Forum
Jan 10, 2008 at 3:33 PM
Hi,

I am working on course tracking application and I need to access SLK to know whether a user has completed the course.

This is my code

Stack<IDisposable> disposer = new Stack<IDisposable>();
const string ParentWebUrl = "https://216........./";
SPUser LearnerID;
SPUserToken LearnerToken;

SPSite spsite = new SPSite(ParentWebUrl);

LearnerID=spsite.RootWeb.AllUsers"Domain\\username";
LearnerToken=LearnerID.UserToken;
disposer.Push(spsite);

SPSite Packagesite = new SPSite(ParentWebUrl, LearnerToken);

SPWeb spWeb = Packagesite.OpenWeb();
disposer.Push(spWeb);

SlkStore slkStore = SlkStore.GetStore(spWeb);

I am getting following error when I execute the above line.

Microsoft.SharePointLearningKit.SlkNotConfiguredException: This site is not configured to use SharePoint Learning Kit. Administrators can use SharePoint Central Administration to configure SharePoint Learning Kit.
at Microsoft.SharePointLearningKit.SlkSPSiteMapping.GetMapping(Guid spSiteGuid)
at Microsoft.SharePointLearningKit.SlkStore.GetStore(SPWeb spWeb)


Do I miss anything???
Coordinator
Jan 10, 2008 at 5:45 PM
Edited Jan 10, 2008 at 5:47 PM
I suspect that the SPSite you're passing to SlkStore.GetStore is not the SPSite you think it is. One of the things I noticed when playing around with similar code is that the SharePoint (not SLK) APIs for for SPSite and SPWeb are what I would consider to be "wierd" APIs in that they try and "interpret as best they can what they think you meant". While this might be helpful in some cases, to me it makes things much more complex because the data you get out from the data you pass in is much less determinate.

Put it in a debugger and inspect the properties of spsite, Packagesite, and spWeb to see if they are what you'd expect them to be based on your input. You'll probably find a problem when you do this.

For what it's worth, I'm writing very similar code to this right now -- I'm setting assignment completed status based on inputs from a web service. I ended up writing directly to the SharePointLearningKit tables rather than going through the SLK/SharePoint API because of some of the complexities of how things work. Especially for reporting applications (like yours?), you may find opening the database directly is a simpler approach.

BTW, if you haven't looked at the new LINQ functionality for database work that's in .NET 3.5, you might want to. I'm using it for my project and it's just amazingly cool. IMHO, LINQ is going to go down in computer history as one of the major innovations of the 2000-2010 decade.
Jan 10, 2008 at 7:26 PM
Thanks Jay.

I tried to access database directly, but still I am getting the same error.

I used following line

DBMapping = SlkSPSiteMapping.GetMapping(Packagesite.ID);

And the error is

Microsoft.SharePointLearningKit.SlkNotConfiguredException: This site is not configured to use SharePoint Learning Kit. Administrators can use SharePoint Central Administration to configure SharePoint Learning Kit.
at Microsoft.SharePointLearningKit.SlkSPSiteMapping.GetMapping(Guid spSiteGuid)

I checked for SLK Database and it was running fine.

Do I need check any other??
Coordinator
Jan 10, 2008 at 7:54 PM
When I said 'talk to the database', I meant something like:

SqlConnection con = new SqlConnection("Server=localhost; Database=SharePointLearningKit");

AKA using ADO or LINQ to talk directly to SQL Server from your (ASP.NET?) code.

Did you check to see whether Packagesite is what you think it should be?
Jul 21, 2009 at 11:48 AM

Hello there.

I'm having the exact same problem. I've checked the database, and the SPWeb i'm using to get the store, is the SPWeb, referring to the correct site.

I've vhecked the site ID in the table SiteSettingsItem in SharepointLearningKit Database, and it checks out with the site ID i'm getting with spWeb.Site.ID.

 

Did someone find the answer to this problem? I'm using source code indicated in the API documentation.

Thanks in advance,

Rafael

Coordinator
Jul 21, 2009 at 2:47 PM

Try running

slkadm.exe -o enummappings

to see if the site is configured correctly.

More info on slkadm on my blog at http://blog.salamandersoft.co.uk/index.php/2009/02/slkadm-for-sharepoint-learning-kit/

Richard

SLK Coordinator

http://blog.salamandersoft.co.uk

Jul 21, 2009 at 3:56 PM

Hello Richard.

Thank you for the quick answer.

I ran the slkadm command, and the site is indeed configured for SLK.

Maybe i'm doing something wront, so here is the code i'm trying to run:

SPUser spUser;
                String loginName = "myDomain\\myUser";
                String webUrl = "http://myMoss/sites/mySite/";
                using (SPSite anonymousSite = new SPSite(webUrl))
                {
                    using (SPWeb rootWeb = anonymousSite.RootWeb)
                    {
                        spUser = rootWeb.AllUsers[loginName];
                        
                    }
                }
                Console.WriteLine(spUser.LoginName);
                using (SPSite spSite = new SPSite(webUrl, spUser.UserToken))
                {
                    disposer.Push(spSite);
                    Console.WriteLine(spSite.ID);
                    using (SPWeb spWeb = spSite.OpenWeb())
                    {
                        disposer.Push(spWeb);
                        Console.WriteLine(spWeb.Site.ID);
                        SlkStore slkStore = SlkStore.GetStore(spWeb);
                        Console.WriteLine(slkStore.SPSiteGuid);
                    }
                }

 

Note that the Console.Writeline() in the code are only for control, and that Console.WriteLine(spSite.ID); actually returns the site ID in the database, and the id returned in the slkadm command.

Also, the user i'm using in the code, is the site administrator. I'm using this user in the code, and i'm using it to run the program (this user is domain admin, and a local machine admin).  As i said, this source is taken from the SLK API documentation.

Best regards,

Rafael

Coordinator
Jul 21, 2009 at 4:58 PM

What happens if you try to get the store in the first block i.e.

 

using (SPSite anonymousSite = new SPSite(webUrl))
{
                    using (SPWeb rootWeb = anonymousSite.RootWeb)
                    {
                        spUser = rootWeb.AllUsers[loginName];

                        SlkStore slkStore = SlkStore.GetStore(spWeb);
                        Console.WriteLine(slkStore.SPSiteGuid);
                        
                    }

}

 

BTW, you don't need the disposer object as you are using using blocks. Can't stand it (disposer object) myself. I find it makes the code harder to read when there's a perfectly good built in mechanism for doing it anyway.

Jul 21, 2009 at 5:28 PM

Hi Richard.

I've tried, but the result is the same. It's the same error message as always.

Microsoft.SharePointLearningKit.SlkNotConfiguredException: This site is not conf
igured to use SharePoint Learning Kit. Administrators can use SharePoint Central
 Administration to configure SharePoint Learning Kit.
   at Microsoft.SharePointLearningKit.SlkSPSiteMapping.GetMapping(Guid spSiteGui
d)
   at Microsoft.SharePointLearningKit.SlkStore.GetStore(SPWeb spWeb, String lear
ningStoreUserKey)
   at Microsoft.SharePointLearningKit.SlkStore.GetStore(SPWeb spWeb)
   at SLKTest.Program.Main(String[] args) in D:\Rafael\Projectos\NETLAB\SLKTest\
Program.cs:line 57

Line 57 is:

SlkStore slkStore = SlkStore.GetStore(rootWeb);

 

I've installed the assignments webpart, and this works fine. So, the SLK must be well configured, right?

Jul 21, 2009 at 5:52 PM

When i run enumsolutions.cmd from the slk install, i get this in one of the lines:

<ContainsCodeAccessSecurityPolicy>FALSE</ContainsCodeAccessSecurityPolicy>

I don't know what this means, so i was wondering if it as anything to do with this.