Example #1
0
        /// <summary>
        /// Updates the SqlStoredProcedureCollection with any changes made since the last call to Refresh.
        /// Refresh is automatically called once when the SqlTable.StoredProcedures collection is read.
        /// </summary>
        public void Refresh()
        {
            // Force internal refresh of tables
            database.dmoDatabase.GetStoredProcedures().Refresh(false);

            // Clear out old list
            storedProcedures = new ArrayList();

            for (int i = 0; i < database.dmoDatabase.GetStoredProcedures().GetCount(); i++)
            {
                NativeMethods.IStoredProcedure dmoSproc = database.dmoDatabase.GetStoredProcedures().Item(i + 1, "");

                SqlStoredProcedure sproc;

                if (dmoSproc.GetSystemObject())
                {
                    sproc = new SqlStoredProcedure(dmoSproc.GetName(), dmoSproc.GetOwner(), SqlObjectType.System, DateTime.Parse(dmoSproc.GetCreateDate()));
                }
                else
                {
                    sproc = new SqlStoredProcedure(dmoSproc.GetName(), dmoSproc.GetOwner(), SqlObjectType.User, DateTime.Parse(dmoSproc.GetCreateDate()));
                }

                storedProcedures.Add(sproc);

                sproc.dmoStoredProcedure = dmoSproc;
                sproc.database           = this.database;
            }
        }
Example #2
0
        /// <summary>
        /// Adds a new stored procedure to the table with specified name and text.
        /// </summary>
        /// <param name="name">
        /// The name of the stored procedure to add.
        /// </param>
        /// <param name="text">
        /// The text of the stored procedure to add.
        /// The text must contain a valid SQL stored procedure creation statement.
        /// </param>
        /// <returns>
        /// If the operation succeeded, the return value is the stored procedure created.
        /// </returns>
        /// <remarks>
        /// The name in the Text parameter must match the Name parameter.
        /// </remarks>
        public SqlStoredProcedure Add(string name, string text)
        {
            if (name == null || name.Length == 0)
            {
                throw new ArgumentException(SR.GetString("SqlStoredProcedureCollection_MustHaveValidName"));
            }

            if (this[name] != null)
            {
                throw new ArgumentException(String.Format(SR.GetString("SqlStoredProcedureCollection_NameAlreadyExists"), name));
            }

            // Physically add database
            NativeMethods.IStoredProcedure dmoStoredProcedure = (NativeMethods.IStoredProcedure) new NativeMethods.StoredProcedure();
            dmoStoredProcedure.SetName(name);
            dmoStoredProcedure.SetText(text);
            database.dmoDatabase.GetStoredProcedures().Add(dmoStoredProcedure);

            SqlStoredProcedure sproc = new SqlStoredProcedure(dmoStoredProcedure.GetName(), dmoStoredProcedure.GetOwner(), dmoStoredProcedure.GetSystemObject() ? SqlObjectType.System : SqlObjectType.User, DateTime.Parse(dmoStoredProcedure.GetCreateDate()));

            // Set internal properties
            sproc.dmoStoredProcedure = dmoStoredProcedure;
            sproc.database           = this.database;

            // Add to private list
            storedProcedures.Add(sproc);

            return(sproc);
        }