Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web.config AspNetCoreModuleV2 SQLite unable to open database file #6117

Closed
SeriaWei opened this Issue Dec 25, 2018 · 10 comments

Comments

Projects
None yet
4 participants
@SeriaWei
Copy link

SeriaWei commented Dec 25, 2018

Unable to open database file

web.config AspNetCoreModuleV2 SQLite throw the exception "unable to open database file".

ConnectionString

"ConnectionString": "Data Source=Database.sqlite"

But when i change to use AspNetCoreModule or change the connection string to Data Source=D:\\ZKEACMS\\Database.sqlite the application run correctly.

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\ZKEACMS.WebHost.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>
  </location>
</configuration>
@SeriaWei

This comment has been minimized.

Copy link
Author

SeriaWei commented Dec 25, 2018

IIS Version :10.0

@pakrym

This comment has been minimized.

Copy link
Member

pakrym commented Dec 26, 2018

It's probably due to the CurrentDirectory issue: #4206. Here is our recommended workaround for now: https://github.com/aspnet/Docs/blob/master/aspnetcore/host-and-deploy/aspnet-core-module/samples_snapshot/2.x/CurrentDirectoryHelpers.cs. Call CurrentDirectoryHelpers.SetCurrentDirectory() first thing in Program.Main. This will be fixed in a patch.

@SeriaWei

This comment has been minimized.

Copy link
Author

SeriaWei commented Dec 26, 2018

I found that, System.IO.Directory.GetCurrentDirectory() not return the right directory
image

@SeriaWei

This comment has been minimized.

Copy link
Author

SeriaWei commented Dec 26, 2018

@pakrym Thanks.

SeriaWei added a commit to SeriaWei/ZKEACMS that referenced this issue Dec 26, 2018

@pakrym

This comment has been minimized.

Copy link
Member

pakrym commented Dec 29, 2018

I assume the workaround has resolved your issue. Feel free to reopen otherwise.

@pakrym pakrym closed this Dec 29, 2018

@ericjohannsen

This comment has been minimized.

Copy link

ericjohannsen commented Mar 13, 2019

How would the work-around help when attempting to create a SQLite database from Package Manager Console?

PM> Update-Database
SQLite Error 14: 'unable to open database file'.

@pakrym

This comment has been minimized.

Copy link
Member

pakrym commented Mar 13, 2019

@ericjohannsen the issue in this thread is not related to your problem and neither is the workaround. It's only applicable to applications running in IIS using AspNetCore InProcess hosting model. Can you please file your issue in http://github.com/aspnet/EntityFrameworkCore

@ericjohannsen

This comment has been minimized.

Copy link

ericjohannsen commented Mar 13, 2019

@pakrym Are you certain? The issue is that EF receives its configuration from AspNetCore using this line:

    services.AddDbContext<MyContext>(options =>
        options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

I can make it work by hacking appsettings.json like this:

  "ConnectionStrings": {
    //"DefaultConnection": "Filename=./db/my.db"
    "DefaultConnection": "Data Source=E:/dev/myproject/wwwroot/db/my.db"
  },

Have a look at this documentation,

If your startup project is an ASP.NET Core app, the tools try to obtain the DbContext object from the application's service provider.

The tools first try to obtain the service provider by invoking Program.BuildWebHost() and accessing the IWebHost.Services property.

If you still feel the issue is not related to how AspNetCore sets the current directory, please provide enough context so I can explain to the EF Core team why the problem resides with them.

@jkotalik

This comment has been minimized.

Copy link
Member

jkotalik commented Mar 13, 2019

I would make sure that you are running on ASP.NET Core 2.2.2 and check again.

@ericjohannsen

This comment has been minimized.

Copy link

ericjohannsen commented Mar 14, 2019

I'm running on ASP.NET Core 2.2.3.

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