0
我能夠從sql服務器執行下面的sql命令創建這個,但有什麼辦法可以使用C#代碼執行此命令嗎?如何從C#代碼創建sql server主密鑰和證書?
SQL命令......
USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'rajesh';
Go
Use Master
BACKUP MASTER KEY TO FILE = 'C:\Users\HP USER\Desktop\Encrypt\KEYs'
ENCRYPTION BY PASSWORD = 'rajesh'
GO
Use Master
CREATE CERTIFICATE mytestcert
WITH SUBJECT = 'Mytestcertificate'
Use Master
BACKUP CERTIFICATE mytestcert TO FILE = 'C:\Users\HP USER\Desktop\Encrypt\mytestcert.cer'
GO
CREATE DATABASE dbShop ;
GO
USE dbShop
GO
CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM = AES_256
ENCRYPTION BY SERVER CERTIFICATE [mytestcert]
ALTER DATABASE test
SET ENCRYPTION ON;
爲什麼不能只用C#執行這些命令,就像執行任何其他SQL命令一樣? – RBarryYoung
我自己並沒有這樣做,但['Smo'](http://technet.microsoft.com/en-us/library/Microsoft.SqlServer.Management.Smo.aspx)命名空間似乎有幾個可能的樣子類,如'MasterKey'。 –