locked
SSMS + BIDS Troubleshooting RRS feed

  • Question

  • So I am very close to achieving my goal but keep on getting errors when I am executing my task on Visual Studio.
    For my initial code  I got an error saying "OBJECT REFERENCE NOT SET TO AN INSTANCE OF AN OBJECT"

    So I assumed that the NULL's weren't showing and added if/else statements now I am getting an error once again for my updated code:

    using System;

    using System.Data;

    using System.Collections.Generic;

    using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

    using Microsoft.SqlServer.Dts.Runtime.Wrapper;

    using System.DirectoryServices.AccountManagement;

    using System.DirectoryServices;

    [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]

    public class ScriptMain : UserComponent

    {

        public override void PreExecute()

        {

            base.PreExecute();

            /*

              Add your code here for preprocessing or remove if not needed

            */

        }

        public override void PostExecute()

        {

            base.PostExecute();

      

        }

        public override void CreateNewOutputRows()

        {

            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "1111111");

            UserPrincipal user = new UserPrincipal(ctx);

            PrincipalSearcher ps = new PrincipalSearcher(user);

            /* Initializing variables */

            string badLogonCount;

            DateTime? accountLockoutTime;

            string firstName;

           DateTime? accountExpirationDate;

            string Telephone;

            DateTime? LastLogon;

             string PWDneverexpires;

            string PWDnotrequired;

       

            /* Get values from Active Directory and assign to local variable and handle nulls */

            foreach (UserPrincipal found in ps.FindAll())

            {

        

                if (!(found.BadLogonCount == null))

                {

                    badLogonCount = Convert.ToString(found.BadLogonCount);

                }

                else

                {

                    badLogonCount = "unknown";

                }

         

                if (!(found.Name == null))

                {

                    firstName = Convert.ToString(found.Name);

                }

                else

                {

                    firstName = "unknown";

                }

             

                if (!(found.AccountExpirationDate == null))

                {

                    accountExpirationDate = Convert.ToDateTime(found.AccountExpirationDate);

                }

                else

                {

                    accountExpirationDate = Convert.ToDateTime("1900-01-01 00:00:00.000");

                }

                if (!(found.VoiceTelephoneNumber == null))

                {

                    Telephone = Convert.ToString(found.VoiceTelephoneNumber);

                }

                else

                {

                    Telephone = "unknown";

                }

                if (!(found.LastLogon == null))

                {

                    LastLogon = Convert.ToDateTime(found.LastLogon);

                }

                else

                {

                    LastLogon = Convert.ToDateTime("1900-01-01 00:00:00.000");

                }

    if (!(found.PasswordNeverExpires == null))

                {

                    PWDneverexpires = Convert.ToString(found.PasswordNeverExpires);

                }

                else

                {

                    PWDneverexpires = "unknown";

                }

                if (!(found.PasswordNotRequired == null))

                {

                    PWDnotrequired = Convert.ToString(found.PasswordNotRequired);

                }

                else

                {

                    PWDnotrequired = "unknown";

                }

             

                /* set values to output rows defined in SSIS */

                myOutputBuffer.AddRow();

                myOutputBuffer.badLogonCount = badLogonCount;

         

                myOutputBuffer.expirationDate = Convert.ToDateTime(accountExpirationDate);

                myOutputBuffer.firstname = firstName;

                myOutputBuffer.TelephoneNumber = Telephone;

          

                myOutputBuffer.lastLogon = Convert.ToDateTime(LastLogon);

                 myOutputBuffer.PWDneverexpires = PWDneverexpires;

                myOutputBuffer.PWDnotrequired = PWDnotrequired;

            }

     

    Now I am getting an error saying

    "Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'

    I am also getting a warning on these two lines:

    if (!(found.PasswordNotRequired == null))
    if (!(found.PasswordNeverExpires == null)) The result of this expression is always 'false' since a value of type 'bool' is never equal to a 'null' of type 'bool?'

    Tuesday, July 21, 2015 7:43 PM

All replies

  • Hey guys any ideas how to get rid of the above errors?
    Wednesday, July 22, 2015 2:25 AM