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
3 Asked on January 26, 2021 by rankinstudio
1 Asked on January 26, 2021
6 Asked on January 26, 2021 by pau
2 Asked on January 26, 2021 by pad
0 Asked on January 26, 2021 by bsharer-app-share-books
3 Asked on January 26, 2021 by jan-dunder
0 Asked on January 26, 2021 by sai-reddy
0 Asked on January 26, 2021 by mohamed-mohsen
0 Asked on January 26, 2021 by luis-ramon-ramirez-rodriguez
1 Asked on January 26, 2021 by donmiguelsan
0 Asked on January 26, 2021 by ahmed-ghrib
0 Asked on January 25, 2021 by bill-ewing
2 Asked on January 25, 2021 by colla
2 Asked on January 25, 2021 by codecutter
0 Asked on January 25, 2021 by farshad
1 Asked on January 25, 2021 by machineghost
error handling firefox developer tools google chrome devtools javascript reactjs
3 Asked on January 25, 2021 by noah-stahl
Get help from others!
Recent Questions
Recent Answers
© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP