Solved

Permission Denied Error Accessing SQLServerCE File

Posted on 2016-09-24
6
15 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
REXEX help Part 2 2 23
SQL Server 2012 r2 - Varible Table 3 24
vb.net 1 month apart 11 29
Unable to connect C# program to an SQL database - Exception occurs. 4 19
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.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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