C
C#15mo ago
Arpit Sirohi

❔ The ConnectionString property has not been initialized error coming on accessing the sql server

Hi! I am trying to access mysql server from MVC Core application with EF Core .I am running sql server in my local docker container .Also I am on visual studio Mac. When I try to access the server I am getting the ConnectionString property has not been initialized error . The connection string works fine when I connect to azure data studio . The following are the screenshots for the appsettings.json and program.cs respectively . Please let me know if you want to know anymore details.
9 Replies
phaseshift
phaseshift15mo ago
what code do you use to pass the connection string to the DbContext?
E_kenny47
E_kenny4715mo ago
Is it not supposed to be "localhost:1433" instead of "localhost,1433"
Arpit Sirohi
Arpit Sirohi15mo ago
@phaseshift I am using builder services in program.cs to configure the dbcontext connection .The following is the screenshot for the same
Arpit Sirohi
Arpit Sirohi15mo ago
@E-kenny I think localhost :1433 and localhost,1433 are similiar I have seen localhost,1433 also working fine. Did give localhost:1433 a try but it did not work .
E_kenny47
E_kenny4715mo ago
In your program.cs line 10, correct the spelling of "ConnectionStrings"
Henkypenky
Henkypenky15mo ago
services.AddDbContext<BethanysPieShopDbContext>(options => {
options.UseSqlServer(Configuration.GetConnectionString("BethanysPieShopDbContextConnection"));
});
services.AddDbContext<BethanysPieShopDbContext>(options => {
options.UseSqlServer(Configuration.GetConnectionString("BethanysPieShopDbContextConnection"));
});
Arpit Sirohi
Arpit Sirohi15mo ago
Thanks a lot kenny , can't believe I didn't see the incorrect spelling Thanks a lot HenkyPenky
Arpit Sirohi
Arpit Sirohi15mo ago
So now I am getting error A network-related or instance-specific error occurred while establishing a connection to SQL Server. It seems to be due to docker image of sql .Do I need to make changes to docker ?
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.