[Last Call] Learn how to a build a cloud-first strategyRegister Now


SecurityException Permission denied

Posted on 2006-04-06
Medium Priority
Last Modified: 2008-01-09
I have a C# windows application written using VS .NET 2005.  In my application I am referencing a COM dll that has a procedure named SendToDDC.  When my code calls this procedure, I am getting an unhandled SecurityException 'Permission denied'.  I call this procedure mulitple times in my code.  The first call always works successfully, but any subsequent calls receive the exception.  I do not need to know how to handle the exception, but I would like to know what I need to do to avoid it.  I need to call this procedure or my application is useless.

Question by:afg1976
  • 2
  • 2
LVL 11

Expert Comment

ID: 16399813
Hard to say without knowing what the com dll does, perhaps it's like the CDONTS mail object and needs to be destroyed and recreated each time you use it?

Author Comment

ID: 16401270
The dll sends data to an ERP system over TCP and then gets a response and sends it back to my application.  The dll has no procedures for destroying the object.  I do have line: ddc = null;  

Is there a better way to do what you are indicating?  I have included my code that calls the Procedure SendToDDC below.  I also have the details of the exception below that.  

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace PowerTAP
    class cDDCManager
        private string DDC_DELIMETER = ConfigurationSettings.AppSettings["DDCDelimeter"].ToString();
        private string DDC_HOSTIP = ConfigurationSettings.AppSettings["DDCHostIP"].ToString();
        private int DDC_PORT = Convert.ToInt16(ConfigurationSettings.AppSettings["DDCPort"]);
        private int DDC_TIMEOUT = Convert.ToInt16(ConfigurationSettings.AppSettings["DDCTimeout"]);
        private bool DDC_LOOPBACK = Convert.ToBoolean(ConfigurationSettings.AppSettings["LoopBack"]);
        private string DDC_LOGFILE = ConfigurationSettings.AppSettings["LogFile"].ToString();
        private int DDC_SESSIONID = Convert.ToInt16(ConfigurationSettings.AppSettings["DDCSessionId"]);
        public int errorCount = 0;
        public enum ddcFunction

        private string[] p_returnValues;

        public string returnValue(int idx)
                return p_returnValues[idx];
                return "0";

        public string callDDC(ddcFunction function, string[] ddcParams)
            string defaultServer = "tihrac863m000";
            DisusDDC.DDCcom ddc = new DisusDDC.DDCcom();
            ddc.DDCDelimiter = DDC_DELIMETER;
            ddc.DDCHostIP = DDC_HOSTIP;
            ddc.DDCPort = DDC_PORT;
            ddc.DDCSessionId = DDC_SESSIONID;
            ddc.DDCTimeout = DDC_TIMEOUT;
            ddc.LoopBack = DDC_LOOPBACK;
            ddc.LogFile = DDC_LOGFILE;


            ddc.DDCServer = defaultServer;
            ddc.DDCFunction = function.ToString();

            for (int i = 0; i <= ddcParams.GetUpperBound(0); i++)
                ddc.SetDDCParam(ref ddcParams[i]);

            if (ddc.SendToDDC())
                p_returnValues = new string[ddc.ResponseCount];
                for (int i = 0; i < ddc.ResponseCount; i++)
                    p_returnValues[i] = ddc.GetResponse(i+1);
                return "Success";
                errorCount = ddc.ErrorCount;
                p_returnValues = new string[errorCount];
                for (int i = 0; i < errorCount; i++)
                    p_returnValues[i] = ddc.GetError(i+1);
                return "Error";
            ddc = null;

Also, here is the Exception details:
System.Security.SecurityException was unhandled
  Message="Permission denied"
       at DDC.DDCcomClass.SendToDDC()
       at PowerTAP.cDDCManager.callDDC(ddcFunction function, String[] ddcParams) in C:\Documents and Settings\andrew\My Documents\Visual Studio 2005\Projects\PowerTAP\PowerTAP\cDDCManager.cs:line 68
       at PowerTAP.EmployeeAction.btnTimeIn_Click(Object sender, EventArgs e) in C:\Documents and Settings\andrew\My Documents\Visual Studio 2005\Projects\PowerTAP\PowerTAP\EmployeeAction.cs:line 108
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at PowerTAP.Program.Main() in C:\Documents and Settings\andrew\My Documents\Visual Studio 2005\Projects\PowerTAP\PowerTAP\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
LVL 11

Accepted Solution

LordWabbit earned 2000 total points
ID: 16401429
Mmmm, personal folders have security restrictions on them by default (so another non admin user logging on cannot see your docs etc.) try changing the projects folder to allow full control to everyone, the com dll might be trying to write to the local directory and does not have the same sort of disk permissions the calling .net app has.

Author Comment

ID: 16403552
Yes, thank you.  There is a Log file the dll is trying to write.  It could not access the directory for the log file.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question