Задача сценария служб SSIS при возникновении производственной исключительной ситуации Использование Microsoft.SharePoint.client - PullRequest
0 голосов
/ 23 апреля 2020

Я пытаюсь удалить элементы списков Microsoft Sharepoint с помощью задачи скрипта SSIS C#. Он отлично работает на моем локальном компьютере. Я установил Microsoft.SharePoint. dll на моем компьютере для выполнения этой задачи.

Ниже описано, что я сделал для задачи сценария пакета служб SSIS.

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using Microsoft.SharePoint.Client;
using System.Linq;
using System.Text;
using System.Net;
using System.Security;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace ST_d55693ffa58249c9b326e10762830927
{

    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {


        public void Main()
        {

            try
            {                

                string siteUrl = "https://comapany.sharepoint.com/sites/sinfo/IT_TEAM/";


                using (ClientContext clientContext = new ClientContext(siteUrl))
                {
                    var passWord = new SecureString();

                    foreach (char c in "******************".ToCharArray()) passWord.AppendChar(c);

                    clientContext.Credentials = new SharePointOnlineCredentials("user@comapany.com", passWord);

                    Web oWebsite = clientContext.Web;

                    List oList = oWebsite.Lists.GetByTitle("TEST_S");                    
                    ListItemCollectionPosition licp = null;
                    clientContext.Load(oList);
                    clientContext.ExecuteQuery();
                    int itemCount = oList.ItemCount;

                    while (true)
                    {
                        CamlQuery query = new CamlQuery();
                        query.ViewXml
                            = @"<View><ViewFields><FieldRef Name='ID'/></ViewFields><RowLimit>250</RowLimit></View>";

                        query.ListItemCollectionPosition = licp;
                        ListItemCollection items = oList.GetItems(query);
                        clientContext.Load(items);
                        clientContext.ExecuteQuery();
                        licp = items.ListItemCollectionPosition;
                        itemCount -= items.Count;

                        foreach (ListItem itm in items.ToList())
                        {
                            itm.DeleteObject();
                        }

                        clientContext.ExecuteQuery();
                        if (licp == null)
                        {
                            break;
                        }
                    }
                }

            }
            catch (Exception e)
            {

                SqlConnection con = new SqlConnection("Data Source=PROD_20;Initial Catalog=TEAM_DATA;Integrated Security=SSPI;");
                con.Open();

                string qry = "INSERT INTO ASSIST.ERROR_LOGS(PACKAGE,METHOD,MESSAGE,TIME_OCCURED) VALUES(@Package,@Method,@Message,@Time);";
                SqlCommand cmd = new SqlCommand(qry, con);
                cmd.Parameters.Add("@Package", SqlDbType.VarChar, 20);
                cmd.Parameters.Add("@Method", SqlDbType.VarChar, 30);
                cmd.Parameters.Add("@Message", SqlDbType.NVarChar, 255);
                cmd.Parameters.Add("@Time", SqlDbType.DateTime);

                cmd.Parameters["@Package"].Value = "PRE_SP";
                cmd.Parameters["@Method"].Value = "PRE MAIN";
                cmd.Parameters["@Message"].Value = e.Message.ToString();
                cmd.Parameters["@Time"].Value = DateTime.Now;
                cmd.ExecuteNonQuery();
                con.Close();
            }

            Dts.TaskResult = (int)ScriptResults.Success;
        }

        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
    }
}

После развертывания пакета на производственном сервере. Выдает исключение, как Exception было выброшено целью вызова.

это что-то связанное с учетной записью службы Prod для доступа на сайт Sharepoint.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...