Unable to decrypt Stored Procedure
Jacquers
Posts: 10
Hi,
I have recently started using the sdk (fully licensed) and have found that it's not able to decrypt or script stored procedures (in the target db) that have been encrypted, so it cannot deploy changes for them. The database is 2008R2 and I'm using admin credentials.
Using the same databases and credentials SQL Compare UI is able to view, decrypt and script changes to those SPs.
Is there an option I'm missing?
Thanks,
Jacques
I have recently started using the sdk (fully licensed) and have found that it's not able to decrypt or script stored procedures (in the target db) that have been encrypted, so it cannot deploy changes for them. The database is 2008R2 and I'm using admin credentials.
Using the same databases and credentials SQL Compare UI is able to view, decrypt and script changes to those SPs.
Is there an option I'm missing?
Thanks,
Jacques
Comments
I assume if my 1st issue of not being able to decrypt the SP in the target db is solved, then this one will be solved as well.
Adding AddWithEncryption isn't viable because that will encrypt all the stored procedures, not just the ones that are already encrypted.
I find it very strange and frustrating that the ui can decrypt successfully, but the sdk can't.
Make sue the account connecting has db owner rights so it can dump the pages it needs to decrypt.
Check for exceptions; dumping the pages needs the backup reader DLL and that means you have to compile for x86 or it won't work. But you should get an error or badimageformatexception if that's the problem.
using (var sourceDb = new Database())
{
var connectionProperties = new ConnectionProperties
{
ServerName = ".\\sqlexpress",
DatabaseName = "TestDB",
UserName = "sa",
Password = "sapassword"
};
var options = Options.Default | Options.DecryptPost2kEncryptedObjects | Options.AddWithEncryption;
sourceDb.Register(connectionProperties, options);
var sql = new Work().ScriptObject(sourceDb.StoredProcedures[0], Options.Default).ToString();
}
And when calling Comparewith, the result from the messages / warnings is:
The procedure [dbo].[spTest] cannot be decrypted in one or more of the datasources. Its contents cannot be compared and it cannot be synchronized.
The procedure [dbo].[spTest] cannot be decrypted in one or more of the datasources. Its dependencies cannot be exactly identified. The script may fail.
I changed it to use the options you suggested and still no decryption....
I'd like to get it working, but for now I'm getting the create script for the source and manually updating the target if the target is encrypted.
Regards,
Jacques