Stack Overflow Asked by Nathan Nguyen on December 15, 2020
I get an error like this:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 – Could not open a connection to SQL Server)
Here is my apppsetting.json
:
"DBInfo":
{
"Name": "MySQLconnect",
"ConnectionString": "server=localhost;user Id=root;password=root;database=cinemapanda4;"
}
and here is my StartUp.cs
:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSession();
services.AddDbContext<MyContext>(options => options.UseSqlServer(Configuration["DBInfo:ConnectionString"]));
services.AddControllersWithViews();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthorization();
app.UseEndpoints(endpoints => {
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
I’m using MacBook and how can I fix this problem?
Looks like you're trying to use a MySQL database with EF Core, but connecting with SqlServer driver, which won't work. To connect to MySQL, you can use the Pomelo Driver for EF Core.
Configuration for which can be found here: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#3-services-configuration
Answered by sauravsahu on December 15, 2020
2 Asked on December 4, 2021 by lucas-vitor
1 Asked on December 3, 2021 by jake-rankin
3 Asked on December 3, 2021 by hellofanengineer
4 Asked on December 3, 2021 by maimok
2 Asked on December 3, 2021 by sak
1 Asked on December 3, 2021 by chessguy
1 Asked on December 3, 2021 by carrey
0 Asked on December 3, 2021 by rickyk95
3 Asked on December 3, 2021 by aysh
0 Asked on December 3, 2021 by ntakouris
apache beam google cloud dataflow google cloud sql tensorflow tfx
2 Asked on December 3, 2021
1 Asked on December 3, 2021 by kok-how-teh
1 Asked on December 3, 2021 by question3r
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP