当我从Sharepoint 2010 Webservices提取数据时,SQL CLR函数显示错误 [英] SQL CLR function showing error when i am fetching data from Sharepoint 2010 Webservices

查看:122
本文介绍了当我从Sharepoint 2010 Webservices提取数据时,SQL CLR函数显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过asmx webservices从sharepoint 2010列表中获取数据,但是当我在任何列中都没有数据时,它在sql上显示以下错误:让我们说 ows_ClientContactPerson列没有任何记录,那么如果有,它将在错误以下给出

Hi am fetching data from sharepoint 2010 list by asmx webservices but when i there is no data in any column it says below error on sql: Lets says "ows_ClientContactPerson" column has not any record then it will give me below error if has then it will not give me error..

Msg 6260, Level 16, State 1, Line 2
An error occurred while getting new row from user defined Table Valued Function : 
System.ArgumentException: Column 'ows_ClientContactPerson' does not belong to table  row.
System.ArgumentException: 
 at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName)
at SharePointClients.GetClientsItemInfo(Object obj, SqlString& ID, SqlString& Title,     SqlString& ParentClientVertical, SqlString& NoOfStores, SqlString& Complexity, SqlString&  Location, SqlString& ClientContactPerson, SqlString& IsActive).

请在创建程序集时查看我的C#代码。

Please see my C# code from when i am creating my assemblies.

using System;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Security.Principal;
using System.Net;
using System.Xml;

public class SharePointClients
{
[SqlFunction(SystemDataAccess = SystemDataAccessKind.Read, FillRowMethodName = "GetClientsItemInfo")]
public static IEnumerable GetClientsItems(SqlString url, SqlString listName, SqlString viewName)
{
    DataTable t = new DataTable();
    WindowsImpersonationContext ctx = null;

    WindowsIdentity id = SqlContext.WindowsIdentity;

    try
    {
        ctx = id.Impersonate();

        WSS.Lists svc = new WSS.Lists();
        svc.Url = url.ToString();

        //svc.Credentials = new NetworkCredential("barley", "pass@word1", "VS");
        svc.Credentials = CredentialCache.DefaultNetworkCredentials;
        XmlNode node = svc.GetListItems(listName.ToString(), viewName.ToString(), null, null,"150000", null, null);
        XmlTextReader rdr = new XmlTextReader(node.OuterXml,
                                    XmlNodeType.Element, null);
        DataSet ds = new DataSet();
        ds.ReadXml(rdr);
        t = ds.Tables[1];
    }
    finally
    {
        if (ctx != null)
            ctx.Undo();
    }

    return t.Rows;
}

public static void GetClientsItemInfo(
                    object obj,
                    out SqlString ID,
                    out SqlString Title,
                    out SqlString ParentClientVertical,
                    out SqlString NoOfStores,
                    out SqlString Complexity,
                    out SqlString Location,
                    out SqlString ClientContactPerson,
                    //out SqlString ClientContactEmailID,
                    //out SqlString PhoneNumber,
                    out SqlString IsActive)

{
    DataRow r = (DataRow)obj;
    ID = new SqlString(Convert.ToString(r["ows_ID"]));
    Title = new SqlString(Convert.ToString(r["ows_Title"]));
    ParentClientVertical = new SqlString(Convert.ToString(r["ows_ParentClientVertical"]));
    NoOfStores = new SqlString(Convert.ToString(r["ows_NoOfStores"]));
    Complexity = new SqlString(Convert.ToString(r["ows_Complexity"]));
    Location = new SqlString(Convert.ToString(r["ows_Location"]));
    ClientContactPerson = new SqlString(Convert.ToString(r["ows_ClientContactPerson"]));
    //ClientContactEmailID = new SqlString(Convert.ToString(r["ows_ClientContactEmailID"]));
    //PhoneNumber = new SqlString(Convert.ToString(r["ows_PhoneNumber"]));
    IsActive = new SqlString(Convert.ToString(r["ows_IsActive"]));
}
}

请在下面查看我的SQL函数创建代码

Please see below my SQL function creation code

/****** Object:  UserDefinedFunction [dbo].[fn_GetListItemsClients]    Script Date: 10/19/2012 05:45:43 ******/
CREATE FUNCTION [dbo].[fn_GetListItemsClients](@SiteUrl [nvarchar](256), @ListName [nvarchar](256), @viewName [nvarchar](256))
RETURNS  TABLE (    
[ID] [nvarchar](50) NULL,
[Title] [nvarchar](256) NULL,
[ParentClientVertical] [nvarchar](256) NULL,
[NoOfStores] [nvarchar](256) NULL,
[Complexity] [nvarchar](256) NULL,
[Location] [nvarchar](256) NULL,
[ClientContactPerson] [nvarchar](256) NULL,
--[ClientContactEmailID] [nvarchar](70) NULL,
--[PhoneNumber] [nvarchar](70) NULL,
[IsActive] [nvarchar](256) NULL

) WITH EXECUTE AS CALLER
AS 
EXTERNAL NAME [PMTFunction].[SharePointClients].[GetClientsItems]
GO

,请在下面找到我在哪里g选择命令

and please find below where i am using select command

 select * from    dbo.fn_GetListItemsClients('http://wks10953:1000/_vti_bin/Lists.asmx','Clients','')

这真的很重要,请帮助我。.

This is really important, Please help me..

推荐答案

检查DataRow是否包含必需列,如下所示,为每个列使用跟随代码库,以避免将来出现错误。

Check if DataRow contains required column as follows, use follow code base for each column to avoid future errors.

if (r.Table.Columns.Contains("ows_ClientContactPerson"))

ClientContactPerson = new SqlString(Convert.ToString(r["ows_ClientContactPerson"]));

else

ClientContactPerson = new SqlString(string.Empty);

这篇关于当我从Sharepoint 2010 Webservices提取数据时,SQL CLR函数显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆