2

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"?

Nkosi
249k38 gold badges471 silver badges505 bronze badges
asked Jan 16, 2021 at 16:32
2
  • i just realized that i posted the incomplete connection string. I edited the question to contain the correct string. Commented Jan 16, 2021 at 16:42
  • i created the mysql db in the mysql workbench and i am hosting it locally Commented Jan 16, 2021 at 16:43

3 Answers 3

3

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.

answered Jan 16, 2021 at 16:47
0
0

Your connection string missing server name:

"server=;user id=root;database=;allowuservariables=True;password=password;persistsecurityinfo=True"

to

"server=localhost;user id=root;database=;allowuservariables=True;password=password;persistsecurityinfo=True"

if the server is localhost other wise you need to specify the server ip address.

answered Jan 16, 2021 at 16:38
0

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.

answered Jan 16, 2021 at 16:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.