0

Im using Visual Studio Mac. Im working on a asp.net core web api with sqlite database. it works fine in localhost. but doesn't work on host server. it gives 500 internal server error. I published it from a windows visual studio as ftp. I think my internal error is because of my sqlite configuration. its:

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite("Filename=./MyData.db"));

I think this configuration doesn't work in host and I have no idea about it. I just published it. please help me with it.

2
  • Check the exception that is thrown on the server. It should give you direction for the fix. Commented Mar 20, 2018 at 18:49
  • it gives me this error : SQLite Error 1: 'no such table: MyTable' Commented Mar 21, 2018 at 1:09

1 Answer 1

1

I'd suggest you to:

  • Instead of using relative path on filename config, try using the absolute path.

Note: If it works, I'd recommend you to use

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(String.Format("Filename={0}/MyData.db", AppDomain.CurrentDomain.BaseDirectory));

As you're using './MyData.db', I believe 'AppDomain.CurrentDomain.BaseDirectory' is going to be enough, other than that, you must use your correct file location.

[Solved]

  • Add this statement to the method you're calling.

    try { //YOURCODE } catch (Exception e) { return StatusCode(500, $"An error has ocurred. Ex: e.InnerException.Message}"); }

  • Check the error message (no such table: MyTable)

  • Create the table.

Problem solved.

Best Regards

Sign up to request clarification or add additional context in comments.

9 Comments

Your app generates any kind of log? Can you post here?
I published it on a host. And I test it with postman. It only gives me 500 internal server error. But other requests that dont related to the database work fine.
I think you should output the error that is happening so we can have a better idea on what's going on.
Would you please tell me how to do that. I have no idea. Thanks.
Add the following try catch on the method you're calling. try { //YOURCODE } catch (Exception e) { return StatusCode(500, $"An error has ocurred. Ex: {e.InnerException.Message}"); }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.