Skip to content
This repository has been archived by the owner. It is now read-only.

SQLite under IIS Express requires Administrator privileges #132

Closed
jwdavidson opened this issue Sep 2, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@jwdavidson
Copy link

commented Sep 2, 2015

An attempt to run an application accessing an Sqlite db in VS2015 Community as a regular user with IIS Express fails with an error 14: "unable to open database."

The error does not occur if VS2015 Community was opened with Administrator privileges.

The error also does not occur if the same application is run using WebListener as a regular user.

This is more informational than a bug report, as it took me a while to determine what the error really was (need a Windows 10 capable SysInternals).

@natemcmaster

This comment has been minimized.

Copy link
Member

commented Sep 10, 2015

Could be a file permissions error.

Also, I've seen this error with high load web applications producing a deadlock on opening the file.

@jwdavidson

This comment has been minimized.

Copy link
Author

commented Sep 10, 2015

The only load I had was to create the Identity tables, add one role, one user and one user/role. Not much of a load. This was on an i7 Windows 10 box with 8 GB ram. I was using VS2015 Community

@natemcmaster

This comment has been minimized.

Copy link
Member

commented Sep 10, 2015

@jwdavidson and what about file permissions?

@jwdavidson

This comment has been minimized.

Copy link
Author

commented Sep 10, 2015

There are 3 accounts that have permission on the db file and all 3 have Full Control. The accounts are System, my login and Administrators. The permissions are default.

@natemcmaster

This comment has been minimized.

Copy link
Member

commented Sep 10, 2015

This is likely related to #55. SQLite uses Environment.CurrentDirectory as its basepath, which for IIS is C:\Program Files (x86)\IIS Express.

@natemcmaster

This comment has been minimized.

Copy link
Member

commented Sep 10, 2015

To ensure the db file is in your application directory, make sure to set the path.

    public class Startup
    {
        private IApplicationEnvironment _appEnv;

        public Startup(IApplicationEnvironment appEnv)
        {
            _appEnv = appEnv;
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddEntityFramework()
                .AddSqlite()
                .AddDbContext<MyContext>(
                    options => { options.UseSqlite($"Data Source={_appEnv.ApplicationBasePath}/data.db"); });
        }
}
@jwdavidson

This comment has been minimized.

Copy link
Author

commented Sep 11, 2015

That tip on how SQLite sets CurrentDirectory above explains where the database went initially. After I couldn't find it used a FullPath to set the path. That may have caused the requirement for admin rights.

I decided to use SQL Server for the savings in development time and will return to using SQLite probably with beta8 release. This should leave some hints for those who follow and want to keep trying SQLite for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.