Esempio n. 1
0
        public void Dispose()
        {
            // Do NOT remove certificate for concurrent consistency. Certificates are used for other test cases as well.
            foreach (string connectionStr in DataTestUtility.AEConnStringsSetup)
            {
                SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(connectionStr);
                using (SqlConnection conn = CertificateUtility.GetOpenConnection(false, sb))
                {
                    using (SqlCommand cmd = new SqlCommand($"drop table {encryptedTableName}", conn))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = $"drop procedure {encryptedProcedureName}";
                        cmd.ExecuteNonQuery();
                    }
                }

                // Only use traceoff for non-sysadmin role accounts, Azure accounts does not have the permission.
                if (DataTestUtility.IsNotAzureServer())
                {
                    CertificateUtility.ChangeServerTceSetting(true, sb);
                }
            }
        }
Esempio n. 2
0
        public void TestCommandOptionWithNoTceFeature(string connectionString)
        {
            SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(connectionString);

            CertificateUtility.ChangeServerTceSetting(false, sb);  // disable TCE on engine.
            using (SqlConnection conn = CertificateUtility.GetOpenConnection(false, sb, fSuppressAttestation: true))
            {
                using (SqlCommand cmd = new SqlCommand(ExceptionGenericErrorFixture.encryptedProcedureName, conn, null, SqlCommandColumnEncryptionSetting.Enabled))
                {
                    SqlParameter param = cmd.Parameters.AddWithValue("@c1", 2);
                    cmd.CommandType = CommandType.StoredProcedure;
                    string expectedErrorMessage = "SQL Server instance in use does not support column encryption.";
                    InvalidOperationException e = Assert.Throws <InvalidOperationException>(() => cmd.ExecuteNonQuery());
                    Assert.Contains(expectedErrorMessage, e.Message);
                }
            }
            // Turn on TCE now
            CertificateUtility.ChangeServerTceSetting(true, sb);  // enable tce
        }