Link to home
Start Free TrialLog in
Avatar of rkulp
rkulpFlag for United States of America

asked on

Permission Denied Error Accessing SQLServerCE File

In VB 2013 I am accessing a SQLServerCE 3.5 file with the following connection string in app.config:

    <connectionStrings>
        <add name="IncentiveEval.My.MySettings.RIMSIIConnectionString"
            connectionString="Data Source=|DataDirectory|\RIMSII.sdf"
            providerName="Microsoft.SqlServerCe.Client.3.5" />
    </connectionStrings>

Open in new window


This has worked great on several computers but now I'm getting an access denied error indicating I don't have permission to access the db. This also happens when running as administrator. The db is in
    Public gDatabasePath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\IncentiveEval\"

Open in new window

In the ApplicationEvents Startup I have the following:
            If My.Computer.FileSystem.FileExists(gDatabasePath + "RIMSII.sdf") Then
                AppDomain.CurrentDomain.SetData("DataDirectory", gDatabasePath)
                File.SetAttributes(gDatabasePath + "RIMSII.sdf", FileAttributes.Normal)
            End If

Open in new window


 As a test, I set the permissions to allow full control to all users. This does not make any difference.

 The installation package creates the required folders if they don't already exist. So, what have I done wrong and what is best practice in this situation?
SOLUTION
Avatar of funwithdotnet
funwithdotnet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rkulp

ASKER

The problem may not be in this folder rather in the installation package and even the program:
  1. Subfolder was not created by installation package
  2. Program was looking for the file in the wrong place.

Clearly, I have some work to do. Thanks for your help. I'll get back soon (I hope).
Avatar of rkulp

ASKER

funwithdotnet,

Well, I cannot gain access to C:\ProgramData at all, whether I am logged in as user or administrator. That is why the folder was not created. This has happened on two computers, one a Win 8.1 and the other a Win 10, both running 64-bit OS. I was able to install the program successfully on a Win 10 computer with the 32-bit OS.

I ensured that the file was not in the place that the error message had said it could not find it, either on the development computer or the end-user's computer. The code never searches anywhere but C:\ProgramData\IncentiveEval. I can't explain the error message.

Playing with permissions on the installation package does not change anything. Even logged on as administrator, I cannot display the folders in C:\ProgramData.

The only difference between the Windows 10 computers that deny permission and those that don't seems to be whether the last Windows 10 update has been installed. The computer I installed the program on this morning had not been rebooted to install the update. The one that did not allow permission yesterday had been rebooted to install the update. Interesting, but probably not the real cause. It is worth looking into.
Thanks for your interest. I'll keep you posted.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rkulp

ASKER

This worked on the other computer. I will consider the problem solved.
Avatar of rkulp

ASKER

I figured it out and listed the steps that solved the problem. funwithdotnet's suggestions pointed me in the right direction. I am very appreciative.