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"?
-
i just realized that i posted the incomplete connection string. I edited the question to contain the correct string.Kellogs– Kellogs2021年01月16日 16:42:23 +00:00Commented Jan 16, 2021 at 16:42
-
i created the mysql db in the mysql workbench and i am hosting it locallyKellogs– Kellogs2021年01月16日 16:43:26 +00:00Commented Jan 16, 2021 at 16:43
3 Answers 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.
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.
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.
Explore related questions
See similar questions with these tags.