Пример #1
0
        public static DataSet GetObjectPermissions(
            ObjectTag tag,
            bool isExplicit
            )
        {
            DataSet ds = null;

            try
            {
                using (SqlConnection connection = new SqlConnection(Program.gController.Repository.ConnectionString))
                {
                    // Open the connection.
                    connection.Open();

                    // Setup the params.
                    SqlParameter paramSnapshotId     = new SqlParameter(ParamSnapshotId, tag.SnapshotId);
                    SqlParameter paramDbId           = new SqlParameter(ParamDbId, tag.DatabaseId);
                    SqlParameter paramClassId        = new SqlParameter(ParamClassId, tag.ClassId);
                    SqlParameter paramParentObjectId = new SqlParameter(ParamParentObjectId, tag.ParentObjectId);
                    SqlParameter paramObjectId       = new SqlParameter(ParamObjectId, tag.ObjectId);
                    SqlParameter paramPermissionType = new SqlParameter(ParamPermissionType, (isExplicit ? "X" : "E"));

                    // Create command object, and fill the dataset.
                    using (SqlCommand cmd = new SqlCommand(QueryObjectPermissions, connection))
                    {
                        // Set the command object.
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.CommandTimeout = SQLCommandTimeout.GetSQLCommandTimeoutFromRegistry();
                        cmd.Parameters.Add(paramSnapshotId);
                        cmd.Parameters.Add(paramDbId);
                        cmd.Parameters.Add(paramClassId);
                        cmd.Parameters.Add(paramObjectId);
                        cmd.Parameters.Add(paramPermissionType);

                        // Create the data adapter object.
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            // Fill the dataset.
                            ds = new DataSet();
                            da.Fill(ds);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ds != null)
                {
                    ds.Dispose();
                }
                ds = null;

                MsgBox.ShowError(ErrorMsgs.CantGetServerObjectPermissions, ex);
            }

            return(ds);
        }
Пример #2
0
        public static DataSet GetDatabasePrincipalPermissions(
            ObjectTag tag
            )
        {
            DataSet ds = null;

            try
            {
                using (SqlConnection connection = new SqlConnection(Program.gController.Repository.ConnectionString))
                {
                    // Open the connection.
                    connection.Open();

                    // Setup the params.
                    SqlParameter paramSnapshotId = new SqlParameter(ParamSnapshotId, tag.SnapshotId);
                    SqlParameter paramDbId       = new SqlParameter(ParamDbId, tag.DatabaseId);
                    SqlParameter paramUid        = new SqlParameter(ParamUid, tag.ObjectId);

                    // Create command object, and fill the dataset.
                    using (SqlCommand cmd = new SqlCommand(QueryDatabasePrincipalPermissions, connection))
                    {
                        // Set the command object.
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(paramSnapshotId);
                        cmd.Parameters.Add(paramDbId);
                        cmd.Parameters.Add(paramUid);

                        // Create the data adapter object.
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            // Fill the dataset.
                            ds = new DataSet();
                            da.Fill(ds);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ds != null)
                {
                    ds.Dispose();
                }
                ds = null;

                MsgBox.ShowError(ErrorMsgs.CantGetDbPrincipalPermissions, ex);
            }

            return(ds);
        }