Friday, October 8, 2021

 I had the misfortune of needing to know the value of the header in excel for any specific ordinal position.  This is code that gives you those header values using sql.


DROP TABLEIF EXISTS #tmp_letters;

CREATE TABLE #tmp_letters

             (
                          id     INT IDENTITY(1,1) ,
                          letter CHAR(1)
             )INSERT INTO #tmp_letters
            (
                        letter
            )
SELECT 'A'
UNION ALL
SELECT 'B'
UNION ALL
SELECT 'C'
UNION ALL
SELECT 'D'
UNION ALL
SELECT 'E'
UNION ALL
SELECT 'F'
UNION ALL
SELECT 'G'
UNION ALL
SELECT 'H'
UNION ALL
SELECT 'I'
UNION ALL
SELECT 'J'
UNION ALL
SELECT 'K'
UNION ALL
SELECT 'L'
UNION ALL
SELECT 'M'
UNION ALL
SELECT 'N'
UNION ALL
SELECT 'O'
UNION ALL
SELECT 'P'
UNION ALL
SELECT 'Q'
UNION ALL
SELECT 'R'
UNION ALL
SELECT 'S'
UNION ALL
SELECT 'T'
UNION ALL
SELECT 'U'
UNION ALL
SELECT 'V'
UNION ALL
SELECT 'W'
UNION ALL
SELECT 'X'
UNION ALL
SELECT 'Y'
UNION ALL
SELECT 'Z';


DROP TABLEIF EXISTS #tmp_letter_data;CREATE TABLE #tmp_letter_data
             (
                          id      INT IDENTITY(1,1) ,
                          batchid INT ,
                          letters VARCHAR(255)
             )INSERT INTO #tmp_letter_data
            (
                        batchid ,
                        letters
            )
SELECT Batch = 1 ,
       letter
FROM   #tmp_lettersDECLARE @BatchID INT = 1;WHILE(
(
       SELECT Count(*)
       FROM   #tmp_letter_data) < 1020)
BEGIN
  PRINT 'Working it batches'
  DECLARE @Letter      VARCHAR(10)
  DECLARE @NextBatchID INT = @BatchID + 1;
  DECLARE mycursor CURSOR FOR
  SELECT   letters
  FROM     #tmp_letter_data
  WHERE    batchid = @BatchID
  ORDER BY id ASC
  OPEN mycursor
  FETCH next
  FROM  mycursor
  INTO  @Letter
  WHILE @@FETCH_STATUS = 0
  BEGIN
    DECLARE @message VARCHAR(4000);
    PRINT ' '
    SELECT @message = 'Letter PRINT: ' + Cast(@Letter AS VARCHAR(255))
    PRINT @message
    INSERT INTO #tmp_letter_data
                (
                            batchid ,
                            letters
                )
    SELECT      Batch =       2 ,
                tld.letters + ltrs.letter
    FROM        #tmp_letter_data tld
    CROSS apply
                (
                       SELECT letter
                       FROM   #tmp_letters l ) AS ltrs
    WHERE       tld.letters = @Letter
    FETCH next
    FROM  mycursor
    INTO  @Letter
  END
  CLOSE mycursor;
  DEALLOCATE mycursor
  SET @BatchID = @BatchID + 1;
END

Friday, July 16, 2021

SSIS DB not loading

Right now you have tried to update your server and move from one machine to another. You have tried to set trustworthy to on, you have set the ownership to sa.  Nothing has worked. You even have used your super secret password and set master key decryption. 

Here is the way to get this to work. The secret sauce below is to create your SSISDB catalog, empty, and create it with the SAME password that you are going to use when you mount your old version of the database.  This is unintuitive, and I hate it.  But this is what worked for my team.

1.  CREATE THE SSIS CATALOG USING THE WIZARD

     1a.  IN THE WIZARD put the password you had for the original database.
2.  Now that it is made, pull in the back up of the original database into the system.
3.  Now that the backup is pulled in.

Run the following commands:


OPEN master Key decryption by password = '<your password>';
ALTER Master Key ADD encryption by Service Master Key

ALTER AUTHORIZATION ON DATABASE::SSISDB TO sa;
ALTER DATABASE SSISDB SET TRUSTWORTHY ON

The error this fixes is:

An error occurred in the Microsoft .NET Framework while trying to load assembly id 65537. The server may be running out of resources, or the assembly may not be trusted. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: System.IO.FileLoadException: Could not load file or assembly 'microsoft.sqlserver.integrationservices.server, Version=14.0.0.0,