SharePoint Development - Timer Job Creation

That's the funny thing..the code works when it's a local SP install and a SQL box on the same machine or same domain but because the server where the live data is being kept is remote it isn't working :\.

I'm thinking it might have something to do with permissions but not sure where as the secure store is working (wouldn't as I wouldn't be able to see the data when opening the list..)
 
Edit :
Anyone seen this error before? Have given the user read access to the authenticated users group and all the columns exist. Thoughts?
I would suggest the following

1) Get the ULS viewer.
2) Open ULS viewer on live server, then use Open from File.
3) Execute the code and with the Correlation ID (Filter > equals > paste ID AND make sure you don't have spaces before or after) read what happened.

You might find some more info there.
 
That's the funny thing..the code works when it's a local SP install and a SQL box on the same machine or same domain but because the server where the live data is being kept is remote it isn't working :\.

I'm thinking it might have something to do with permissions but not sure where as the secure store is working (wouldn't as I wouldn't be able to see the data when opening the list..)

sjoe, permissions are a bit scary. Under what user is the application running that is doing the insert? You might have access but the the context under which the package or application runs may not be. It could be an actual user or it could be something like domainname\computername$ that needs contribute access to that list.
 
sp9dvn.png
- ULS Screencapture Of The Error
np1ee9.png
- Following entry

Googling for possible solution..
 
Last edited:
I know right.. :( Still looking for solutions BUT I wonder if someone changed the name on a SQL table column(??), would the name of the column remain the original but appear to be renamed much like on SharePoint? Hope you understand me..
 
I know right.. :( Still looking for solutions BUT I wonder if someone changed the name on a SQL table column(??), would the name of the column remain the original but appear to be renamed much like on SharePoint? Hope you understand me..

Did you try to compare the lists and their items with SPM? (sharepoint manager)

One of the replication software I'm testing gives the same error on a discussion board. The problem it seems is that somehow the lists got "confused" and the items are the same, but different. When I look at the names for the same item between the two lists they are not the same. This could be part of the problem maybe somehow during insert new item there is a discrepancy.

That is however how far I've gotten into the problem and what the support is saying to me. It's exactly the error as "The given key was not present in the dictionary."
 
I know right.. :( Still looking for solutions BUT I wonder if someone changed the name on a SQL table column(??), would the name of the column remain the original but appear to be renamed much like on SharePoint? Hope you understand me..

SQL doesnt behave that way. You could use http://www.u2u.be/res/tools/camlquerybuilder.aspx. There is only a 2007 version, but you can use the webservices portion to see what the columns come back as. I havent checked for any other tools thats 2010 compliant. I've used this version successfully before to see what the column names come back as by doing a simple query. Maybe that would help?

Does your app work if you write from your machine to the production server and only fails when its scheduled? Or its not running at all on the new environment? Depending on your set up, column names could be case sensitive, so have a look at that.
 
Well this is how it works so far :

Local (Dev Laptop) + Local SQL(Using backup of Live data) = Works! :)
Local (Dev Laptop) + Remote Production SQL = "The given key was not present in the dictionary."
 
hmmm... with normal lists I make a copy (creates an .stp file) to the template gallery and then use that to create my list on the production side. That way I know they are exactly the same. However I dont know know if that would work with your type of list. Is the SQL collation the same on both instances? Though if it works locally it should be the same.

Maybe try connecting to the remote sql server itself, without the sharepoint portion and see if you can access or write something. that way we know its not the sql portion that is giving an error.
 
Yes, it would. If you want to write to it you would need those types of permissions.
 
But I'm not writing to the SQL table at all.. :\

You are, but not "directly". See the job you execute will run as a certain user account and that account needs to have proper rights. Now you can achieve this by using (which I should have mentioned before) elevated privileges. That might solve your issue on the remote machine HOWEVER there is a few things you should know about using elevated privileges (EP).

For example

Joe opens the list, the list is opened as Joe.
List is opened under EP, now the list is not same as the current user, but it is as EP would be.

This is all dandy if you just wan to do things that doesn't require running as the logged in user where you need to do things under that account or against that account. Just be careful this, you can google this to get full extend.
 
Will give that a gander..

EDIT : After speaking to my Senior, he suggested using the List.asmx service.

Any of you guys have experience with this?

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Xml;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            var listServiceClient = new SharePointServices.Lists();
            listServiceClient.Url = "http:///_vti_bin/lists.asmx";
            listServiceClient.Credentials = new System.Net.NetworkCredential("", "", "");

            //var CopyListDataQuery = new System.Text.StringBuilder();

            var listQueryBuilder = new System.Text.StringBuilder();

            listQueryBuilder.Append("     <Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
            listQueryBuilder.Append("         <OrderBy>");
            listQueryBuilder.Append("              <FieldRef Name=\"Customer\" />");
            listQueryBuilder.Append("         </OrderBy>");
            listQueryBuilder.Append("    </Query>");

            //System.Xml.XmlNode ndListView = listServiceClient.GetListAndView("TestDB_XML", "");
            //string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
            //string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;

            //System.Xml.XmlDocument Doc = new System.Xml.XmlDocument();
            //System.Xml.XmlElement batchCopy = Doc.CreateElement("Batch");
            //batchCopy.SetAttribute("OnError", "Continue");
            //batchCopy.SetAttribute("ListVersion", "1");
            //batchCopy.SetAttribute("ViewName", "{17DD3DD6-A871-4822-AF17-62634EC069F6}");
            //batchCopy.InnerXml = "<Method ID='1' Cmd='New'>" +
            //                                "<Field Name='Title'>Added item</Field></Method>";


            var queryDoc = new XmlDocument();
            queryDoc.LoadXml(listQueryBuilder.ToString());

            var listItems = listServiceClient.GetListItems("Test", string.Empty, queryDoc.DocumentElement, 
                null, string.Empty, null, string.Empty);



            foreach (XmlNode item in listItems.FirstChild.NextSibling.ChildNodes)
            {
                var Entry = new
                {
                    Customer = item.NextSibling.Attributes["ows_Customer"].Value,
                    GivenName = item.NextSibling.Attributes["ows_givenName"].Value,
                    FamilyName = item.NextSibling.Attributes["ows_familyName"].Value,
                    RequestId = int.Parse(item.NextSibling.Attributes["ows_requestId"].Value)
                };
       
            }

        }


    }
}
 
Last edited:
Will give that a gander..

EDIT : After speaking to my Senior, he suggested using the List.asmx service.

Any of you guys have experience with this?

Not with List.asmx though, but I used search.asmx from an external site. We had major authentication issues since kerberos was not set up on our environment and sharepoint internally have double hop authentication happening. So you might specify network credentials properly, but it didn't authenticate. Our only solution at that point was to set everything anonymous. So test your scenario first before you do all the dev.
 
Edit : Got everything working with the help of my lead and senior :) and ofcourse you guys :) Will post the code up early monday morning :)
Have a great weekend guys.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Xml.Linq;
using System.Xml;
using SP = Microsoft.SharePoint.Client;

namespace List
{
    class ListsManipulations : SPJobDefinition
    {

        public ListsManipulations()

            : base()
        {

        }

        public ListsManipulations(string jobName, SPService service, SPServer server, SPJobLockType targetType)

            : base(jobName, service, server, targetType)
        {

        }

        public ListsManipulations(string jobName, SPWebApplication webApplication)

            : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        {

            this.Title = "List Manipulation";

        }

        public override void Execute(Guid ContentDbId)
        {
            {
                var listServiceClient = new ListServicesWEB.Lists();
                listServiceClient.Url = "http://site/_vti_bin/lists.asmx";
                listServiceClient.Credentials = new System.Net.NetworkCredential("username", "password", "doman");

                var listQueryBuilder = new System.Text.StringBuilder();

                listQueryBuilder.Append("     <Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
                listQueryBuilder.Append("         <OrderBy>");
                listQueryBuilder.Append("              <FieldRef Name=\"Customer\" />");
                listQueryBuilder.Append("         </OrderBy>");
                listQueryBuilder.Append("    </Query>");

                System.Xml.XmlNode ndListView = listServiceClient.GetListAndView("custom list", "");
                string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
                string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;

                System.Xml.XmlDocument Doc = new System.Xml.XmlDocument();
                System.Xml.XmlElement batchCopy = Doc.CreateElement("Batch");
                // batchCopy.SetAttribute("OnError", "Continue");
                // batchCopy.SetAttribute("ListVersion", "1");
                // batchCopy.SetAttribute("ViewName", "{17DD3DD6-A871-4822-AF17-62634EC069F6}");

                var queryDoc = new XmlDocument();
                queryDoc.LoadXml(listQueryBuilder.ToString());

                var listItems = listServiceClient.GetListItems("external list", string.Empty, queryDoc.DocumentElement,
                    null, string.Empty, null, string.Empty);

                var addItemBuilder = new StringBuilder();
                //References to actual custom list fields 
                addItemBuilder.Append("<Method ID='{0}' Cmd='New'>");
                addItemBuilder.Append("<Field Name='Title'>{1}</Field>");
                addItemBuilder.Append("<Field Name='givenName'>{2}</Field>");
                addItemBuilder.Append("<Field Name='familyName'>{3}</Field>");
                addItemBuilder.Append("</Method>");

                var addItemFormat = addItemBuilder.ToString();

                var itemIndex = 0;

                var doc = XDocument.Parse(listItems.OuterXml);

                var nodes = from c in doc.Descendants(XName.Get("row", "#RowsetSchema"))
                            select new
                            {
                                Customer = c.Attribute("ows_Customer").Value.Replace("&", "&amp;"),
                                GivenName = c.Attribute("ows_givenName").Value,
                                FamilyName = c.Attribute("ows_familyName").Value,
                            };


                var batchItemBuilder = new StringBuilder();

                int batchSize = 500;
                int batchCount = 0;

                foreach (var customer in nodes)
                {
                    batchItemBuilder.AppendFormat(addItemFormat, ++itemIndex, customer.Customer, customer.GivenName, customer.FamilyName);

                    if (++batchCount == batchSize)
                    {
                        batchCopy.InnerXml = batchItemBuilder.ToString();

                        var listItemCreation = listServiceClient.UpdateListItems("customlist", batchCopy);

                        batchCount = 0;
                        batchItemBuilder = new StringBuilder();
                    }
                }

                if (batchItemBuilder.Length > 0)
                {
                    batchCopy.InnerXml = batchItemBuilder.ToString();

                    var listItemCreation = listServiceClient.UpdateListItems("customlist", batchCopy);
                }
            }
        }

    }
}

And here's the code incase anyone ever needs it :)
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X