既存のデータベース (MS SQL 2012) からある種のテンプレートを作成する必要があります。テンプレートには同一のスキーマ (テーブル、インデックス、ロールなど) が含まれている必要がありますが、ソース DB からのデータが含まれていてはなりません。
これを実現するために、Transfer
SMO のクラスを使用しています。現在の転送設定は次のとおりです。
transfer.CopyAllObjects = true;
transfer.CopyAllSynonyms = true;
transfer.CopyData = false;
transfer.Options.WithDependencies = true;
transfer.Options.DriAll = true;
transfer.Options.Triggers = true;
transfer.Options.Permissions = true;
transfer.Options.Indexes = true;
transfer.Options.ContinueScriptingOnError = true;
transfer.Options.SchemaQualifyForeignKeysReferences = true;
transfer.Options.ExtendedProperties = true;
ソース DB のオブジェクトの 1 つはアプリケーション ロールです。このロール用に生成された転送スクリプトは次のようになります。
/* To avoid disclosure of passwords, the password is generated in script. */
declare @idx as int
declare @randomPwd as nvarchar(64)
declare @rnd as float
select @idx = 0
select @randomPwd = N''
select @rnd = rand((@@CPU_BUSY % 100) + ((@@IDLE % 100) * 100) +
(DATEPART(ss, GETDATE()) * 10000) + ((cast(DATEPART(ms, GETDATE()) as int) % 100) * 1000000))
while @idx < 64
begin
select @randomPwd = @randomPwd + char((cast((@rnd * 83) as int) + 43))
select @idx = @idx + 1
select @rnd = rand()
end
declare @statement nvarchar(4000)
select @statement = N'CREATE APPLICATION ROLE [MyRole] WITH DEFAULT_SCHEMA = [dbo], ' + N'PASSWORD = N' + QUOTENAME(@randomPwd,'''')
EXEC dbo.sp_executesql @statement
質問: ソース DB からパスワードを使用してこの役割を転送する方法は? ここでは、この「セキュリティ」は必要ありません。適切な転送オプションが見つかりません。何か不足していますか?