Archive

Archive for the ‘Workarounds’ Category

Sql Server secretly replicating registry keys on startup

October 20, 2011 Leave a comment

Not my find this but such a useful post I thought I’d repost it.

In my situation I had added a certificate’s thumbprint to the SuperSocketNetLib key on a new cluster which, for some reason Sql took a total and utter dislike to.

I thought (in my apparent naïveté) that I could simple remove the thumbprint from the registry, restart Sql and I’d be off and running.

Not so fast though. Every time I’d restart Sql Server it would repopulate the thumbprint back into the Certificate value then fail to start as a result. No matter how many times I rebooted, took the value out of the registry and twisted on my left foot whilst swinging a chicken in the air, Sql Server stubbornly and abjectly refused to stop repopulating the value with the bad certificates thumbprint.

User baby_cheeses on SqlServerCentral.com was able to find the magic formula for stopping Sql Server from magically repopulating the registry.

I amended baby_cheeses answer slightly to fit my situation, and it is…

  1. Remove the Certificate’s thumbprint from the registry.

  2. Start Sql Server using a Net Start MSSqlServer.

  3. Check the registry again and ensure thumbprint hasn’t returned.

  4. Start up Sql Server from within Cluster Administrator

  5. Check registry a third time and remove the thumbprint from the Certificate value.

  6. Move the cluster to another node and watch it start normally.

Like I say, I can’t take credit for this discovery.

Original post is here.

 

UPDATE

Apparently what is happening here is known as Checkpointing, where a copy of the registry is stored on the Quorum. MS gives an official method of avoiding the problem here, although I still think baby_cheeses solution is simpler and involves far less hacking around!

Deploying signed assemblies in a single script

November 18, 2009 Leave a comment

I’ve been writing a set of routines to control my database backups recently and one part of this was a CLR User Defined Data Type I’d created that allows some rudimentary file handling (with the appropriate security). By it’s very nature this assembly required the EXTERNAL ACCESS privilege and this is where the head-scratching came about.

Liking clean install scripts with minimal payloads (single scripts are easier to check into Source Code and deploy across multiple environments) I needed some method of encapsulating the deploy and ensuring the appropriate asymmetric key, users etc. were created. However normally this would require either the key file or the assembly DLL to be copied along with the .Sql script – and this would break my 1 script rule! So next idea was to create the asymmetric key from the assembly directly within Sql server – but I couldn’t do that until I’d installed the assembly which would fail because it required the EXTERNAL ACCESS privilege; Thus leading to another game of Chicken and Egg.

The solution was remarkably obvious – use a temporary SAFE assembly to create the asymmetric key then dispose of it directly afterwards – after all the assembly is only required at this juncture to create the asymmetric key.

The first section of the script deals with previous execution cleanups etc:

  1. Use RandomThunks
  2.  
  3. ————/ Start stage 1 : Drop previous objects /————————————————–
  4.  
  5. If Exists ( Select 1 From sys.assembly_types As T Inner Join sys.schemas As S On T.schema_id = S.schema_id Where T.name = N'SqlFile' And S.Name = N'Maintenance.Database.Archives')
  6.     Drop Type [Maintenance.Database.Archives].SqlFile;
  7.  
  8. If Exists (Select 1 From sys.assemblies Where name = N'RandomThunks.CLR.SqlServerFileUDT' and is_user_defined = 1)
  9.     Drop Assembly [Skipjack.CLR.SqlServerFileUDT];
  10.  
  11. – This next key should never exist when we run this as it's only use to create the asymmetric key before we Grant the External Access right to it.
  12.  
  13. If Exists (Select 1 From sys.assemblies Where name = N'TEMPORARY. DO NOT USE!' and is_user_defined = 1)
  14.     Drop Assembly [TEMPORARY. DO NOT USE!];
  15.     
  16. If Exists ( Select 1 From sys.server_principals Where name = 'SqlServerFileUDTUser' )
  17.     Drop Login SqlServerFileUDTUser;
  18.     
  19. If Exists ( Select 1 From sys.asymmetric_keys Where name = 'SqlServerFileUDTKey' )
  20.     Drop Asymmetric Key SqlServerFileUDTKey;
  21.  
  22. ————/ End stage 1 : Drop previous objects /—————————————————-

And the second part deploys the assembly with the requisite privilege:

  1. ————/ Start stage 2 : Object Creation /——————————————————–
  2.  
  3. Declare @Assembly VarBinary(MAX);
  4. Set @Assembly = 0x4D5A9000030000000
  5.  
  6. If Not Exists ( Select 1 From sys.schemas Where Name = 'Maintenance.Database.Archives')
  7.     Exec sp_ExecuteSql N'Create Schema [Maintenance.Database.Archives]';
  8.  
  9. – Create a temporary assembly that we'll use to build the Asymmetric Key from
  10.  
  11. Create Assembly [TEMPORARY. DO NOT USE!] Authorization dbo
  12.     From @Assembly
  13.     With Permission_Set = Safe;
  14.  
  15. Create Asymmetric Key SqlServerFileUDTKey
  16.     From Assembly [TEMPORARY. DO NOT USE!];
  17.  
  18. – Drop the temporary assembly – it's use is over.
  19.  
  20. Drop Assembly [TEMPORARY. DO NOT USE!];
  21.  
  22. Create Login SqlServerFileUDTUser
  23.     From Asymmetric Key SqlServerFileUDTKey;
  24.  
  25. – This needs to be run at the Server level – encapsulating it in a sp_ExecuteSql allows the script to be DB name agnostic.
  26.  
  27. Exec sp_executeSql N'
  28.     Use master;
  29.  
  30.     Grant External Access Assembly
  31.         To SqlServerFileUDTUser;';
  32.  
  33. – This is the real assembly
  34.  
  35. Create Assembly [Skipjack.CLR.SqlServerFileUDT] Authorization dbo
  36.     From @Assembly
  37.     With Permission_Set = External_Access;
  38.  
  39. Create Type [Maintenance.Database.Archives].SqlFile
  40.     External Name [RandomThunks.CLR.SqlServerFileUDT].SqlFile;
  41.  
  42. ————/ End stage 2 : Object Creation /———————————————————-

Categories: CLR, Sql Server, Workarounds

Unverifiable Passwords with Sql Configuration Manager

February 23, 2009 Leave a comment

This was an odd one and much akin to a previous recent incident I’d had with the configuration manager (albeit this time on a totally different server); this last weekend we had one of our regular ‘let’s all work through the night’ maintenance windows. Such events are never fun to do but made even worse when the strangest of things happen.

This weekend it was the turn of the Sql Configuration Manager and it’s stubborn refusal to validate a new account password. No matter how many times I tried it would not take the new password, regardless if I pasted it in or typed it in. Each time I’d see an entry in the Security log telling me the attempt to logon with the credentials had failed.

Given that it was now getting close to 3AM I decided another approach based off the prior experience; I fired up the Services applet and pasted the password directly in there.

Well, would you Adam and Eve it – it only bloody worked.

Don’t have a good reason or explanation for this one other than – WTF?

Still, whatever it takes.

Sql Server 2005 SP2 No CR’s.

Categories: Sql Server, Workarounds

2005 Configuration manager oddness

January 20, 2009 Leave a comment

I was doing a round of mass service account password changes today on one of our development servers and came across this bit of strangeness; despite making several attempts to update the account and password in the Configuration manager the SSIS service refused not only to start up, but also failed to give any indication as to why (the application logs were horribly silent on anything from either SSIS or even the service manager).

So I went into the back door and fired up the Services applet and refreshed the password in there. One message informing me the account had been granted the ‘Logon as a service’ privilege and the service was up.

What beats me is why the configuration manager refused on multiple times to accept the change. Not saying we should all ignore the config manager from now on but I myself will bear this in mind for future weirdness.

Follow

Get every new post delivered to your Inbox.