script encrypted database object
reven
Posts: 6
hi im trying to script a encrypted database object in sql server 2008 r2 but all I am getting back is
im running it under "sa" and using the following code (note RG is an alias for the RedGate.SQLCompare.Engine name space to avoid a namespace conflict with the rest of my code).
-- Text was encrypted
GO
im running it under "sa" and using the following code (note RG is an alias for the RedGate.SQLCompare.Engine name space to avoid a namespace conflict with the rest of my code).
RG.Database db = new RG.Database(); try { RG.ConnectionProperties connectionProperties = new RG.ConnectionProperties(DbHelper.DbServer, DbHelper.DbDatabase, DbHelper.DbUser, DbHelper.DbPassword); RG.Options options = RG.Options.Default | RG.Options.DecryptPost2kEncryptedObjects | RG.Options.IgnorePermissions | RG.Options.IgnoreWhiteSpace | RG.Options.IgnoreUsers; db.Register(connectionProperties, options); RG.Work work = new RG.Work(); RG.Regions regions = null; switch(Type) { case DbObjectType.StoredProcedure: regions = work.ScriptObject(db.StoredProcedures[ObjectName], options); break; case DbObjectType.Table: regions = work.ScriptObject(db.Tables[ObjectName], options); break; case DbObjectType.Function: regions = work.ScriptObject(db.Functions[ObjectName], options); break; case DbObjectType.Trigger: regions = work.ScriptObject(db.DdlTriggers[ObjectName], options); break; } string script = regions.ToString(); return script; } catch (Exception ex) { Trace.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); return null; } finally { }
Comments
Try that, and post back if the problem persists!
Redgate Software
both of those are done, the BackupReader dll reference is from the same directory/version as the rest of the dlls. even using the same project and changing it from "Tables[0]" to a encrypted stored proc doesn't decrypt it.
What version of the Compare DLL's are you using? Just the ones supplied with the SDK? If so, you might want to grab Compare 8.50 from here: http://www.red-gate.com/supportcenter/G ... rsions.htm then try referencing the DLLs from that.
Redgate Software
Redgate Software
Received extended trial key, using the DLLs
- C:\Program Files (x86)\Red Gate\SQL Compare 9\RedGate.Licensing.Client.dll (v2.50.30.1)
- C:\Program Files (x86)\Red Gate\SQL Compare 9\RedGate.Shared.SQL.dll (v8.50.30.10)
- C:\Program Files (x86)\Red Gate\SQL Compare 9\RedGate.Shared.Utils.dll (v8.50.30.10)
- C:\Program Files (x86)\Red Gate\SQL Compare 9\RedGate.SQLCompare.ASTParser.dll (v9.0.0.51)
- C:\Program Files (x86)\Red Gate\SQL Compare 9\RedGate.SQLCompare.Engine.dll (v9.0.0.51)
- C:\Program Files (x86)\Red Gate\SQL Compare 9\RedGate.SQLCompare.Rewriter.dll (v9.0.0.51)
and using the following code under the "sa" account (database is in a VM and code is on my local box)
and im still getting the result
what am I doing wrong?
I got the same result as you initially, but the following should decrypt the objects:
- add a reference to "RedGate.BackupReader.dll"
- add a reference to "System.Data.SQLite.dll" (the backup reader needs this)
- ensure you compile to "X86" rather than "AnyCPU"
Redgate Software
- C:\Program Files (x86)\Red Gate\SQL Compare 9\RedGate.BackupReader.dll (v1.50.30.9)
- C:\Program Files (x86)\Red Gate\SQL Compare 9\SQLite\System.Data.SQLite.DLL (v1.0.54.0)
platform target is x86.
still getting text is encrypted.