C
C#3mo ago
Mihneas22

Database In ASP.Net Core

Hello! So basically we all know when we create a SQL Database in Visual Studio Community with EF and SQLServer and we can store data there. My question is this: when we add the app to a website like Heroku or a Hosting App in order to publish it to the web, does the database with all the data gets added too or is there a separate process for that? Thanks!
33 Replies
v0fbu1vm
v0fbu1vm3mo ago
No you will have to host the database aswell. If it's an in memory database then no. You don't want an in memory database though. You can for instance use Azure Sql Database. Then your server will connect to it using a connection string.
Mihneas22
Mihneas22OP3mo ago
(localdb)\MSSQLLocalDB; if it's like this it is memory built in or not?
glhays
glhays3mo ago
No not a memory db, that is a lightweight db shipped as part of vs. You can us SqlLite. The SQL database that is a file you can use in your Visual Studio solution is SQLite. SQLite is a self-contained, serverless, zero-configuration, transactional SQL database engine. It stores the entire database in a single file, making it easy to manage and deploy within your solution.
SuperBrain
SuperBrain3mo ago
@Mihneas22 what is your application for and how many people are going to use it at the same time? Also, how is your application using your database? Do you have a large amount of data and do you need multiple users to be able to access the same database at the same time? Depending on how you answer these questions, we can tell you what kind of RDBMS you want/need to use.
Mihneas22
Mihneas22OP3mo ago
Well My application is an API done with Clean Arhitecture
Mihneas22
Mihneas22OP3mo ago
No description
Mihneas22
Mihneas22OP3mo ago
I plan to post my APP on Rapid API so I can't really determine how well it is going to do My application is using the database by retrieving data in order so show to the use. For example let's say the use wants to get a nutritional fact from my API. It will access the database and the retrieve the data
becquerel
becquerel3mo ago
you will probably be fine with sqlite unless you are getting many thousands of users, assuming you have it configured correctly and are using patterns like async/await well azure sql database would be very scalable though, it's just sql server hosted in the cloud for you
Mihneas22
Mihneas22OP3mo ago
yes i did Hello! I am getting error 500 when I posted my api to Azure App Service, the database connection seems to be fine as I check if it works on my local host can anyone help
firewarrior
firewarrior3mo ago
Is there any useful information in the app service logs?
Mihneas22
Mihneas22OP3mo ago
[Error] Microsoft.EntityFrameworkCore.Database.Connection: An error occurred using the connection to database 'MyCalisthenicsAPIDatabase' on server 'tcp:mycalisthenicsapidatabaseidbserver.database.windows.net'
firewarrior
firewarrior3mo ago
I'm guessing the database is accessible from public if you connect to it from you dev machine. Is the firewall on Azure SQL configured to allow access from Azure services?
Mihneas22
Mihneas22OP3mo ago
i dont know wait no it is not but how can I do it
firewarrior
firewarrior3mo ago
on the SQL server under networking, firewall there should be a checkbox to allow azure services access
Mihneas22
Mihneas22OP3mo ago
No description
firewarrior
firewarrior3mo ago
It should be there - one second, I'll spin one up real quick
Mihneas22
Mihneas22OP3mo ago
okay, thanks a lot
firewarrior
firewarrior3mo ago
No description
firewarrior
firewarrior3mo ago
it's underneath your rules
Mihneas22
Mihneas22OP3mo ago
oh that it's checked) it has been like that for default
firewarrior
firewarrior3mo ago
Is that the only log message? If so, can you change the log level to something more verbose? Is the App Service Linux or Windows? If Linux you could e.g. set an environment variable
LOGGING__LOGLEVEL__MICROSOFT.ENTITYFRAMEWORKCORE=Information
LOGGING__LOGLEVEL__MICROSOFT.ENTITYFRAMEWORKCORE=Information
Mihneas22
Mihneas22OP3mo ago
it is windows you know when I created the database
firewarrior
firewarrior3mo ago
Then you'd have to replace the double underscores __ with a colon :. We can also hop in a voice call if you want to
Mihneas22
Mihneas22OP3mo ago
I got a warning message that I have to set something about Managed Identities in order for it wokr work
firewarrior
firewarrior3mo ago
that depends on how you authenticate to Azure SQL
Mihneas22
Mihneas22OP3mo ago
Name and Password
firewarrior
firewarrior3mo ago
it supports both SQL Authentication (username + password) as well as Entra ID with normal users and managed identities
Mihneas22
Mihneas22OP3mo ago
i do it with SQL Auth
firewarrior
firewarrior3mo ago
then you don't need a managed identity
Mihneas22
Mihneas22OP3mo ago
in my connection string I also have the name and the password introduce d and this is why I am saying that on my local host is working but when I try to access it on the website/app service created with azure it does not work or Postman
firewarrior
firewarrior3mo ago
Can you hop on a quick call and show me the configuration?
Mihneas22
Mihneas22OP3mo ago
sure
firewarrior
firewarrior3mo ago
Tutorial: Access data with managed identity - Azure App Service
Secure Azure SQL Database connectivity with managed identity from a sample .NET web app, and also how to apply it to other Azure services.

Did you find this page helpful?