Solved

What is a connection string to sdf in Common Files Folder?

Posted on 2014-10-05
6
292 Views
Last Modified: 2014-10-05
Hello Experts

My Desktop Windows (X86) Application failed on Vista and XP machines because I had an sdf in the Program Files and/or Program Files (x86) folder that was accessed using the connection string:

Dim getSW As New SqlCeConnection("Data Source =" & Application.StartupPath & "\Volume Tables\Softwood\" & lblSW.Text & ".sdf")

That was throwing an error because permissions do not exist.

Since these files will be shared, I assume that I should drop the folder and files into the Common Files Folder for it to work: Feel free to correct me if I am wrong. I have done that using the File System component and it works as far as install goes. What I do not know is how to write a connection string to the location. I tried:

Dim getSW As New SqlCeConnection("Data Source =" & Application.CommonAppDataPath & "\Volume Tables\Softwood\" & lblSW.Text & ".sdf")
   
It does not work. I do not know how to connect to the files in the Common Files Folder. And even if I can connect will users still be locked out from reading sdf files in that location? There is no write access required.

How do I fix this? Using Compact Server 3.5 SP2.

Thanks
0
Comment
Question by:PBLack
  • 3
  • 3
6 Comments
 

Author Comment

by:PBLack
ID: 40362458
I couldn't figure it out so I went with using User's Personal Folder in my compile and then referenced it in my app with System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

It works unless someone has a better option.
0
 
LVL 40
ID: 40362478
Under .NET, Program Files is read-only for users who are not administrators, so you have to move files that will be written to somewhere else.

But CommonAppDataPath is not Common Files. It's not common for all users, it is common for all applications. If you look at what it gives, it is something like C:\ProgramData\JamesBurger\JBBackup\0.5.34.0., Where JamesBurger is the user name, JBBackup is the Application name and then the application version number.

What I do when I need to share files between users is to store them somewhere under C:\Users\Public. Because you are working with different operating systems however, Users can have a different name, such as Documents and Settings. In French it's Utilisateurs. For that reason, you are better to retrieve the name from the OS with the following command: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
0
 
LVL 40
ID: 40362494
I was writing my answer while you posted your solution. A bad one.

First of all, you won't be able to share the files. MyDocuments defaults to the current user.

And worse than that, you are doing a mistake that is too common: My Documents should be used for my documents, not yours. It should be reserved for documents that the user create and Save or Save As. The user does not know what a .mdf or a .sdf is, so it does not belong there. On your side, you risk that the user will delete the database because he's cleaning up and think that these files are useless.

Unfortunately, too many programmers and companies use MyDocuments as an easy way out around the extra security that permeates the systems nowadays. MyDocument as become a mess for most users, with they work mixed up with a lot of stuff that does not belong there.

Do you see Outlook files in My Documents? Do you see the custom dictionaries created in Office? Although the user creates the information in there, he knows nothing about the necessary files and how to manage them. So Microsoft saves then under Program Data, your first idea (Application.CommonAppDataPath). The convention that files created by and for an application, but not directly by the user should be in CommonAppDataPath\CompanyName\ApplicationName.

This is good for files such a the ones mentioned. But in your case, you need to share the files, so a directory that is in the users own personal folder won't cut it. That is why I suggest to store it in the Public folder, because it is shared by everybody without having to change the security on the computer.
0
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.

 

Author Comment

by:PBLack
ID: 40362616
Thank you for the advice about My Documents. I will not be using it. Also, having just spoke with the end user, the files will NOT be shared. In fact he wants it so users can operate independently of each other. I had said only read access. Now he requires Read and Write. Sorry for the confusion.,

So what do I use to put the sdfs in a folder that is unique to the user but still allow read and write access?

Thanks
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40362629
environment.GetFolderPath(environment.SpecialFolder.LocalApplicationData), which will gives you something like "C:\Users\JamesBurger\AppData\Local" (on Windows 7 and more, somewhere in Documents and Settings for XP if my memory is good).

As told before, the convention is to create a subdirectory with the CompanyName\ApplicationName and put the application data there.
0
 

Author Comment

by:PBLack
ID: 40362666
Thank you my good man. You have been a tremendous help. Guys like you are the reason I have been a member here for so many years!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

758 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

19 Experts available now in Live!

Get 1:1 Help Now