C
C#3w ago
Salight

How can i connect to Supabase Database with my .net Api

I couldn't find the answer if you could help me i will be appreciated that
26 Replies
Keswiik
Keswiik3w ago
https://supabase.com/docs/guides/database/connecting-to-postgres they've got an entire guide on how to do it
Connecting to your database | Supabase Docs
Explore the options for connecting to your Postgres database.
Salight
SalightOP3w ago
i tried i was thinking it was not connecting but it actually was but the problem is i cannot send normal post method to database i can send post method but i need to add this to the dbcontext
protected override void OnConfiguring(DbContextOptionsBuilder optionsbuilder)
{
optionsbuilder.UseNpgsql("ConnectionString"
, option =>
{
option.EnableRetryOnFailure();
}
);

base.OnConfiguring(optionsbuilder);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsbuilder)
{
optionsbuilder.UseNpgsql("ConnectionString"
, option =>
{
option.EnableRetryOnFailure();
}
);

base.OnConfiguring(optionsbuilder);
}
cs
option.EnableRetryOnFailure()
cs
option.EnableRetryOnFailure()
without this code it doesn't work and it gives exception again but it registers the data also i waited like 1 minute to register the data
Keswiik
Keswiik3w ago
what exception?
Salight
SalightOP3w ago
InnerException = {"23505: duplicate key value violates unique constraint \"PK_AspNetUsers\"\r\n\r\nDETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information."}
InnerException = {"23505: duplicate key value violates unique constraint \"PK_AspNetUsers\"\r\n\r\nDETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information."}
Keswiik
Keswiik3w ago
That error has nothing to do with failing to connect. It is telling you that you are breaking a unique constraint on whatever table you are modifying for example, trying to insert the same record twice when you require unique names or something similar
Salight
SalightOP3w ago
oh okay thank you for the help
Keswiik
Keswiik3w ago
you should really pay more attention to errors like this as they are usually pretty helpful
Salight
SalightOP3w ago
but it is running really slow why is that
Keswiik
Keswiik3w ago
not something i can diagnose for you ¯\_(ツ)_/¯ you are interacting with a remotely hosted database so it could be any number of things
Salight
SalightOP3w ago
maybe it is because of that thank you i will look into that more deeply
Keswiik
Keswiik3w ago
- slow network on your side - slow network / networking issues on the provider side - not enough resources given to the database so it takes a long time to process data - etc if this is just for simple development you'd probably be better off hosting a postgres database locally very easy to set one up using docker
Salight
SalightOP3w ago
can i use that in production ?
Keswiik
Keswiik3w ago
no, but they are great for development and you shouldn't be developing / writing your software against your production database anyways nor should you be letting client applications connect directly to the database
Salight
SalightOP3w ago
damn it is getting more complex why tho
Keswiik
Keswiik3w ago
because that means anyone with enough time can figure out your database credentials, log in with them, and do whatever they wanted with the data
Salight
SalightOP3w ago
then you are saying u have to use public key and url?
Keswiik
Keswiik3w ago
no, I'm saying your database access should be hidden behind some service / api layer so that clients are not directly communicating with your database what kind of product are you trying to make? what is accessing your database?
Salight
SalightOP3w ago
i mean i don't understand i just asked 5 days ago is it secure to keep my database crediantials in appsettings.json they said it is now you confused me is it this thing i am doing is api
Keswiik
Keswiik3w ago
then you're fine, I said don't let clients connect directly to the database that is not what your API is i still stand by saying that you should be using different databases for development and production though
Salight
SalightOP3w ago
we want to publish a website but we don't know which database we have to use we don't have enough budget so the supabase was free we lean to that
Keswiik
Keswiik3w ago
you are likely not going to get good performance running with the free tier of any database provider not enough for a serious, released product (this is assuming people are paying for it)
Salight
SalightOP3w ago
true but lets just make the start so is it secure to connect the database with connection string?
Keswiik
Keswiik3w ago
yes, assuming that isn't being exposed to clients if it is all hidden behind your API then you're fine
Salight
SalightOP3w ago
then also my appsettings json is in secure too right ?
Keswiik
Keswiik3w ago
yes, that is normal
Salight
SalightOP3w ago
okay then i will dig into the first problem thank you a lot bud you helped me a lot
Want results from more Discord servers?
Add your server