protected override void ProcessRecord() { if (InstanceName == "MSSQLSERVER") { InstanceName = null; } var smo = new Server( this.CreateConnection( ServerName, InstanceName, SQLCredential, EncryptConnection.ToBool(), TrustServerCertificate ) ); this.TestSMO(smo); if (!this.AsObject.ToBool()) { SmoContext.AddConnection(smo, Force.ToBool()); } else { base.WriteObject(smo); } }
static void Main(string[] args) { Console.WriteLine("请选择操作类型: 1----加密 2----解密"); string type = ""; while (true) { type = Console.ReadLine(); if (type == "1" || type == "2") { break; } else { Console.WriteLine("操作错误,请输入1或者2"); } } if (type == "1") { Console.WriteLine("开始加密数据库连接串"); EncryptConnection.EncryptConnectionString(true); Console.WriteLine("加密成功!"); } else if (type == "2") { Console.WriteLine("开始解密数据库连接串"); EncryptConnection.EncryptConnectionString(false); Console.WriteLine("解密成功!"); } else { Console.WriteLine("操作错误,请输入1或者2"); } Console.ReadLine(); }