PublishExecute Database Access Error after publishing through c#

PublishExecute Database Access Error after publishing through c#

mcoH3VZV
Advocate Advocate
313 Views
3 Replies
Message 1 of 4

PublishExecute Database Access Error after publishing through c#

mcoH3VZV
Advocate
Advocate

Hi,

 

I have an intermittent error, which is normally solved upon restarting CAD. It happens on Line 104 below, and the message is 'Database Access Error' with the stack trace below. I think it has to do with losing access to the local C Drive .mdb.

 

Message:

Database Access Error

 

StackTrace: 

at Autodesk.Electrical.Database.AccessDbStore.execQuery(String cmdText, DataTable& dtResult)
   at Autodesk.Electrical.Database.AccessDbProjectStore.getDrawingPropertiesByQuery(Int32 dwgIndex, Collection`1 propertyNames, OrderedDictionary& propertyValues)
   at Autodesk.Electrical.Database.AccessDbProjectStore.getDrawingProperties(Int32 dwgIndex, Collection`1 propertyNames)
   at AceDsProjectStore.getDrawingProperties(AceDsProjectStore* , AceDsDrawingID* dwgId, vector<std::basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> >\,std::allocator<std::basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> > > >* propertyNames, map<std::basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> >\,std::basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> >\,std::less<std::basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> > >\,std::allocator<std::pair<std::basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> > const \,std::basic_string<wchar_t\,std::char_traits<wchar_t>\,std::allocator<wchar_t> > > > >* propertyValues)
   at Autodesk.AutoCAD.Publishing.Publisher.PublishExecute(DsdData dsdData, PlotConfig plotConfig)

 

Let me know if anyone has an idea.

 

        private void PublishPDF(bool bMultipleSets, string tempProjPath, string FileName, string ActiveProjpath, List<string> SelDwgList)
        {
            DsdEntryCollection dsdDwgFiles = new DsdEntryCollection();
            foreach (string s in SelDwgList)
            {
                DsdEntry dsdDwgFile1 = new DsdEntry();

                // Set the file name and layout
                dsdDwgFile1.DwgName = s;
                dsdDwgFile1.Layout = "Model";
                dsdDwgFile1.Title = Path.GetFileName(s);

                // Set the page setup override
                dsdDwgFile1.Nps = "";
                dsdDwgFile1.NpsSourceDwg = "";

                dsdDwgFiles.Add(dsdDwgFile1);
            }

            using (DsdData dsdFileData = new DsdData())
            {
                dsdFileData.DestinationName = $"{ActiveProjpath}CP_PanelName_RevA.pdf";
                dsdFileData.ProjectPath = ActiveProjpath;
                dsdFileData.SheetType = SheetType.MultiPdf;
                dsdFileData.SetDsdEntryCollection(dsdDwgFiles);
                if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings4.dsd"))
                    System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings4.dsd");
                dsdFileData.WriteDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings4.dsd");
            }

            //sProjectMdp is required for hyperlinks in the PDF to work.
            string sProjectMdb = "";
            var proj = GetLispData("c:wd_mdb_get_proj_scratch_dbnam", "nil");
            if (proj != null && proj.Length > 0 && proj[0] != null && proj[0].Value != null)
                sProjectMdb = proj[0].Value.ToString();

            StringBuilder newFile = new StringBuilder();

            string[] file = File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings4.dsd");

            bool bSkipLine = false;

            foreach (string line in file)
            {

                if (bMultipleSets && line.Contains("[Target]"))
                {
                    newFile.Append("[Target]\r\n");
                    newFile.Append("Type=6\r\n");
                    newFile.Append($"DWF={tempProjPath}{FileName}\r\n");
                    newFile.Append($"OUT={tempProjPath}\r\n");
                    newFile.Append("PWD=");
                    bSkipLine = true;
                }

                if (line.Contains("[AutoCAD Block Data]"))
                {
                    bSkipLine = false;

                    newFile.Append("[AcePublish]\r\n");
                    newFile.Append("IncludeBookmarks=TRUE\r\n");
                    newFile.Append("IncludeHyperlinks=TRUE\r\n");
                    newFile.Append("ZoomFactor=50\r\n");

                    //Users can lose access to the mdb path at times (How? - TBD), leading to an error. But the two lines cannot be removed,
                    //because otherwise, the hyperlinks won't work, or anything else that requires the project's mdb for publishing.
                    //This is a temporary fix (because publishes with a loss of mdb access will ignore this now) that requires run time to truly conclude,
                    //but ideally, if the mdb is empty, the user should be forced to restart cad, etc to refresh it for publishing.
                    if (sProjectMdb != "")
                    {
                        newFile.Append("OriginMdbPath = " + sProjectMdb + "\r\n");
                        newFile.Append("TempMdbPath = " + sProjectMdb + "\r\n");
                    }

                    newFile.Append("[PdfOptions]\r\n");
                    newFile.Append("IncludeHyperlinks=TRUE\r\n");
                    newFile.Append("CreateBookmarks=FALSE\r\n");
                    newFile.Append("CaptureFontsInDrawing=TRUE\r\n");
                    newFile.Append("ConvertTextToGeometry=FALSE\r\n");
                    newFile.Append("VectorResolution=1200\r\n");
                    newFile.Append("RasterResolution=400\r\n");
                }

                if (bMultipleSets)
                {
                    if (line.Contains("PromptForDwfName"))
                        newFile.Append("PromptForDwfName=FALSE\r\n");
                    else
                    {
                        if (!bSkipLine)
                            newFile.Append(line + "\r\n");
                    }
                }
                else
                    newFile.Append(line + "\r\n");
            }

            File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings4.dsd", newFile.ToString());

            using (DsdData dsdDataFile = new DsdData())
            {
                dsdDataFile.ReadDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings4.dsd");
                PlotConfig acPlCfg = PlotConfigManager.SetCurrentConfig("DWG to PDF.PC3");
                Autodesk.AutoCAD.ApplicationServices.Application.Publisher.PublishExecute(dsdDataFile, acPlCfg);
            }
        }

 

 

0 Likes
314 Views
3 Replies
Replies (3)
Message 2 of 4

ActivistInvestor
Mentor
Mentor

Have you tried not disposing the DsdData instance (e.g., removing the using() block)?

0 Likes
Message 3 of 4

mcoH3VZV
Advocate
Advocate

I have not. I will try that for a while, thank you.

0 Likes
Message 4 of 4

mcoH3VZV
Advocate
Advocate

Thanks for the suggestion, but it didn't work, as I got the same Exception. Does anyone have another idea?

0 Likes