2
votes

I am building my first ASP.NET Core WebApplication and I am using a MySQL Database for it. After I imported the DB-Context with the EF Core Power Tools I saved the Connection String in the appsettings.json File.

Then I tried to load the Index View of one of the Entity Classes, but I keep getting the following error:

ArgumentException: Keyword not supported: 'allowuservariables'.

Exception Stack Trace

I tried to throw 'allowuservariables=true' out of the Connection String, but then I am getting this error message:

SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Connection String: "server=localhost;user id=root;database=dbname;allowuservariables=True;password=password;persistsecurityinfo=True"

Is something wrong with the Connection String or am I missing an extension to identify "allowuservariables"?

2
i just realized that i posted the incomplete connection string. I edited the question to contain the correct string.Kellogs
i created the mysql db in the mysql workbench and i am hosting it locallyKellogs

2 Answers

3
votes

The code is trying to use SqlConnection to connect to a MySQL database, which won't work.

Make sure you've call UseMySql, not UseSqlServer, in ConfigureServices in your Startup.cs file, as documented here.

0
votes

The error message talks about sql server, not mysql:

SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server.

To me this indicates that you are uding SqlConnection class, which is designed to work with MS SQL Server, not with mysql. You need to use MySqlConnection class to connect to a mysql instance.