Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Validate if a SQL table has records from SSIS 2016

$
0
0

Hi guys,

After transferring tables from one server to another, I want to validate that the tables exists on the destination server and have records in it.  I don't have any problems validating that the tables are there.  However, I tried everything to validate if the tables have records in it, or event the size of it will do, both I can't get it working.

Here is my script:

      public void Main()
        {
            dttables = (Dts.Variables["myDataTables"].Value as DataTable).Copy();
            ValidateTransferredTableExistance(dttables);
            Dts.Variables["BadCount"].Value = badcount;
            Dts.Variables["EmailMessage"].Value = message;

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

        public void ValidateTransferredTableExistance(DataTable dt)
        {
            // Opens a connection to the database 
            Server DestinationSrv = new Server(DestinationServer);
            Database db = DestinationSrv.Databases[DestinationDB];
            Boolean tableExists = false;
            Boolean rowsExists = true;

            message = "We may have encountered problems with the transfer of the table(s) listed below." + Environment.NewLine ;
            message += "Please investigate." + Environment.NewLine + Environment.NewLine;


            // Validate that all tables got transferred
            foreach (DataRow row in dt.Rows)
            {
                string sqlTable = row["transferSchema"].ToString() + '.' + row["transferobject"].ToString();
                tableExists = db.Tables.Contains(row["transferobject"].ToString(), row["transferSchema"].ToString());

                if (tableExists == true)
                {
                    DataTable table = new DataTable();
                    table = db.Tables[sqlTable];
                    rowsExists = (table.Rows.Count == 0)

                    if (rowsExists == true)
                    {
                        message += "- " + table + " is empty." + Environment.NewLine + Environment.NewLine;
                        badcount++;
                    }
                }

                if (tableExists == false)
                {
                    message += "- " + sqlTable + " has not been transferred. Please validate that the table exists on the source server." + Environment.NewLine + Environment.NewLine;
                    badcount++;
                }
            }

        }

 

Do I have to fill the table variable using OLEDB Adapter? I don't want to do that, because some of them have over 1 million records.  So can I somehow get the size/data space used for them?

Thanks a lot in advance for you help :-)

Mylene


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>