*Expert Elite*
Posts: 658
Registered: ‎12-04-2009
Message 1 of 2 (191 Views)

Add Property to .Net Project - PnPDatabaseMode

191 Views, 1 Replies
08-30-2012 01:59 PM

I'm using the following code to add a property to a table.


var prj = PlantApplication.CurrentProject.ProjectParts["Piping"];
                PnPDatabaseMode prevMode = prj.Mode;
                prj.Mode = PnPDatabaseMode.Exclusive;
                using (PnPDatabase db = PnPDatabase.Open(prj.DataCacheFile))
                    PnPTable enginitems = db.Tables["EngineeringItems"];
                    if (enginitems.Columns.Contains(projectcolum))
                    PnPColumn col = new PnPColumn(projectcolum, typeof(string), PnPDatabase.DefaultStringValueLength);
                prj.Mode = prevMode;

However, I get an error in the Datalinksmanager when I try to set the PnPDatabaseMode to Exclusive.  Any ideas?


The PnPDatabaseMode was shared, but the error says it's already opened exclusive.

Dave Wolfe
Isaiah 57:15

ECAD, Inc.
Tips and Tricks on our blog: Process Design, from the Outside

A P3D Authorized Reseller
ADN Support Specialist
Posts: 352
Registered: ‎07-24-2007
Message 2 of 2 (148 Views)

Re: Add Property to .Net Project - PnPDatabaseMode

09-05-2012 01:03 PM in reply to: dave.wolfe

The database is already opened in the project so trying to go exclusive on another instance of PnPDatabase will always fail.


Try changing the code to this:


        [CommandMethod("PNPADDCOL", CommandFlags.Modal)]

        public static void PnPAddCol()


            var prj = PlantApplication.CurrentProject.ProjectParts["Piping"];

            PnPDatabaseMode prevMode = prj.Mode;

            prj.Mode = PnPDatabaseMode.Exclusive;


// commented out wrong code


            var db = prj.DataLinksManager.GetPnPDatabase();



            //using (PnPDatabase db = PnPDatabase.Open(prj.DataCacheFile))


                PnPTable enginitems = db.Tables["EngineeringItems"];

                if (enginitems.Columns.Contains("TestNewCol"))


                PnPColumn col = new PnPColumn("TestNewCol", typeof(string), PnPDatabase.DefaultStringValueLength);





            prj.Mode = prevMode;


Fenton Webb

Developer Technical Services

Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community