Hi Ivona, thanks for your query. I will try to answer with best of my knowledge.
When you have your Database configured as AddOn in Heroku, you run the following command to get the connection details:
heroku config -- app <Your App name>
So in my case it gave below output:
CLEARDB_DATABASE_URL: mysql://f0e3tyh65ca8r7:cyyt37a8@eu-cdbr-east-06.cleardb.net/heroku_72yhg6434ac87yt?reconnect=true
Here,
eu-cdbr-east-06.cleardb.net is the Server
heroku_72yhg6434ac87yt is the Database
f0e3tyh65ca8r7 is the user id
and, cyyt37a8 is the password
I used Heroku’s clearDB MySQL AddOn.
This then can be used in your appsetting.json file under connection string:
“ConnectionString”: {
“SampleDB”: “server=eu-cdbr-east-06.cleardb.net;database=heroku_72yhg6434ac87yt;User ID=f0e3tyh65ca8r7; Password=cyyt37a8”
}
which then you can use in your startup.cs file like below:
services.AddDbContext<SampleDBContext>(opts => opts.UseMySql(Configuration[“ConnectionString:SampleDB”]));
I can see in your query that in your startup.cs file you are using service configuration for SQL Server.
In Heroku AddOn configuration have you added SQL Server or MySQL ? If you have added MySQL then you need to change your configure service function as mentioned as mentioned above by me.
Let me know if this helps.
*Also, I have changed my id / password and these are just dummy values to explain :-)