Solved

Permission Denied Error Accessing SQLServerCE File

Posted on 2016-09-24
6
11 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now