Solved

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

Posted on 2014-10-05
6
295 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

911 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

17 Experts available now in Live!

Get 1:1 Help Now