Solved

Permission Denied Error Accessing SQLServerCE File

Posted on 2016-09-24
6
16 Views
Last Modified: 2016-10-03
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?
0
Comment
Question by:rkulp
  • 5
6 Comments
 
LVL 12

Assisted Solution

by:funwithdotnet
funwithdotnet earned 500 total points
ID: 41814360
The Environment.SpecialFolder.CommonApplicationData folder is accessible to all users, that's it's purpose. Perhaps we should look elsewhere for the issue.

Have you looked at the Properties for the IncentiveEval folder to be sure nothing is amiss?

Have you looked at the properties for the database file on a machine that has throws the error? Just to be sure it isn't blocked or have some unusual permissions?

If neither seem to be the issue, can you post the exact content for the exception? (Excluding any sensitive data of course.) Sometimes a very careful read can point out the issue.

Good luck!
0
 
LVL 1

Author Comment

by:rkulp
ID: 41815032
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).
0
 
LVL 1

Author Comment

by:rkulp
ID: 41816841
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.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 1

Accepted Solution

by:
rkulp earned 0 total points
ID: 41818092
I think I have found the problem and solved it. For some reason, ProgramData on these two computers was set to read only and could not be changed. I had to:
  1. Change ownership of ProgramData to my administrator account (I may have returned ownership to SYSTEM at the end but don't remember at this writing. That is a symptom of my age.)
  2. Created the proper subdirectory with proper permissions
  3. Added users with proper permissions. I also added Everyone with the proper permissions
  4. Unchecked ReadOnly on ProgramData
  5. Ensured the installation package had proper permissions on the files to be installed into the subdirectory. For computers that don't have the subdirectory, I put the proper permissions on the folder to be created.
This seems to have worked on one of the computers. I don't have access to the other one until tomorrow at the earliest. If it works there, I'll consider it solved.
0
 
LVL 1

Author Comment

by:rkulp
ID: 41820228
This worked on the other computer. I will consider the problem solved.
0
 
LVL 1

Author Closing Comment

by:rkulp
ID: 41826027
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.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 76
VB.Net - Not Sure if Multi-threading is What I Need 4 29
How to duplicate form in Visual Studio 2015 2 58
VB.NET Textbox input validation 4 37
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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