Solved

Permission Denied Error Accessing SQLServerCE File

Posted on 2016-09-24
6
20 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 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