none
Application cannot open SQLServerCE 3.5 dB when deployed with VS 2010 Installer RRS feed

  • Question

  • Hi,

    I have written a simple application that reads data from a table in a SQLServerCE 3.5 dB. I deployed it using the VS 2010 installer. When I run it, I get an error message, "Access to the database file is not allowed" and the path to the dB file. It works in the VS IDE. Why am I getting this error? There is no password for the database.

    Thanks,

    Ralph

    Tuesday, April 2, 2013 7:48 PM

All replies

  • Where are you installing the database? If it resides in Program Files, then you won't be able to access it, as that folder structure became protected starting with Windows Vista.

    It's not a password problem. The error says "access to the database file is not allowed", which means you can't even access the file, let alone open the database. 

    RobinDotNet


    Click here to visit my ClickOnce blog!
    Microsoft MVP, Client App Dev

    Friday, April 5, 2013 6:12 PM
    Moderator
  • Hi Ralph65,

    First of all, check if the database installed in the correct location.

    Second, most likely the application doesn't have permission to read/write the database. You can either install it to location with permission or modify the permission during installation, please read my last reply in link below.

    http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/363266b4-89f5-4175-b68c-2b7b06237368/

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 8, 2013 9:12 AM
    Moderator
  • Where are you installing the database? If it resides in Program Files, then you won't be able to access it, as that folder structure became protected starting with Windows Vista.

    It's not a password problem. The error says "access to the database file is not allowed", which means you can't even access the file, let alone open the database. 

    RobinDotNet


    Click here to visit my ClickOnce blog!
    Microsoft MVP, Client App Dev


    Robin, I need to correct this somewhat. The Program Files folder has always been restricted so that only admin users can create or update files there. Even on XP, limited users cannot Modify or Write there. What changed on UAC is that all the apps that previously ran with admin privileges (because almost everyone was an administrator) no longer worked because by default programs do not run with admin privilege when run by a user with admin privileges. The short answer is that these programs always required admin privilege anyway, so they need an admin elevation manifest added to them.

    Phil Wilson

    Tuesday, April 9, 2013 5:52 PM
    Moderator
  • Thank you, not being able to access the dB file because it is in the Program Files (which it was) makes perfect sense!!!!!!!

    This brings up the obvious question: How do I specify where to put it? In the install project, I put in in the ""User's Application Data Folder", built the installer, ran setup, and ran the program, and it couldn't find the dB. I found it in C:\Users\Ralph\AppData\Roaming. In the program, I use "Data Source=|DataDirectory|\PhoneBookDB.sdf" as my connection string.

    Thanks,

    Ralph

    Wednesday, April 10, 2013 1:30 AM
  • Hi Ralph,

    To get roaming folder, you can use the following code.

    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

    http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 11, 2013 8:30 AM
    Moderator
  • Thanks, Bob, but I meant how can I tell the setup project to create a new folder? I read your link, but that did not really tell me how to create a new folder, and have the setup project put the dB in it. I do not want to get into granting special permissions. 

    Thanks,

    Ralph

    Thursday, April 11, 2013 5:06 PM
  • Hi Ralph,

    I thought you already done this. Anyway, please read the following links.

    http://msdn.microsoft.com/en-us/library/s2esdf4x(v=vs.80).aspx

    http://msdn.microsoft.com/en-us/library/x56s4w8x(v=vs.80).aspx

    http://msdn.microsoft.com/en-us/library/4ddxk2ye(v=vs.80).aspx

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 12, 2013 8:32 AM
    Moderator
  • Hi, Bob,

    Thank you for the links, but I'm still having problems.

    I right clicked in the "File System on Target Machine" pain, went to Add Special Folder -> Custom Folder, and created "Database Test Data", and put the dB file in that folder. After building and running setup, there is no Database Test Data folder, and when I run the program, I get the same old error, Access to the database file is not allowed. [file name = C:\Program Files\PhoneBookDB.sdf] PhoneBookDB.sdf is in Program Files with the time and date of the last install. 

    Why wasn't the Database Test Data folder created, and why wasn't PhoneBookDB.sdf in it?


    Thanks,

    Ralph65

    Saturday, April 13, 2013 4:07 AM