Solved

Permission Denied Error Accessing SQLServerCE File

Posted on 2016-09-24
6
8 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Accepted Solution

by:
rkulp earned 0 total points
Comment Utility
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
Comment Utility
This worked on the other computer. I will consider the problem solved.
0
 
LVL 1

Author Closing Comment

by:rkulp
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

763 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

9 Experts available now in Live!

Get 1:1 Help Now