Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to connect to my MySql Workbench database in ASP.NET Core. I'm following a youtube guide where I'm told to write some stuff in the Package Manager Console:
Add-Migration "Initial-Create"
And then:
Update-Database
Now when I run the second command I get this:
Build started...
Build succeeded.
System.ArgumentException: Keyword not supported: 'port'.
at Microsoft.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
at Microsoft.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms)
at Microsoft.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation, Func`2 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Keyword not supported: 'port'.
My connectionstring looks like this:
"AuthDBContextConnection": "Server=localhost;Port=xxxx;Database=xxxx;User ID = xxx;Password=xxxx;Pooling=false;SslMode=none;convert zero datetime=True;Trusted_Connection=True;MultipleActiveResultSets=true"
I've tried googling it and checking stackoverflow for similar questions but can't find the solution. Every solution I've come across I need to change something in the web.config file. The problem is I don't even have a web.config file in my project.
Any ideas?
Thank you!
–
–
–
The error was similar while working with ASP.net core and Database. default database Provider with the ASP.net core is the SQL Server but, in case you are using a different provider, you will find this error.
looking like you are using MySQL DB in your project. update your code like below in your startup.cs file.
public void ConfigureServices(IServiceCollection services)
services.AddDbContext<YourDbContextName>(options =>
options.UseMySql(
Configuration.GetConnectionString("AuthDBContextConnection")));
Don't forget to install NuGet package MySql.Data.EntityFramework
Hope it will resolve your issue.
UPDATE
Your Need these NuGet packages, please install these. it will resolve your issue.
using Microsoft.EntityFrameworkCore;
using MySQL.Data.EntityFrameworkCore.Extensions;
using MySql.Data.EntityFrameworkCore
AGAIN UPDATE
Install these:-
Microsoft.EntityFrameworkCore (v5.0.0 – the latest stable version)
Microsoft.EntityFrameworkCore.Tools (v5.0.0 – the latest stable version)
Pomelo.EntityFrameworkCore.MySql (version 5.0.0-alpha.2)
Your connectionstring look like this:-
"ConnectionStrings": {
"DefaultConnection": "server=localhost; port=3306; database=test; user=root; password=Wxp@Mysql; Persist Security Info=False; Connect Timeout=300"
And Update your startup.csfile:-
public void ConfigureServices(IServiceCollection services)
string mySqlConnectionStr = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContextPool<MyDBContext>(options => options.UseMySql(mySqlConnectionStr, ServerVersion.AutoDetect(mySqlConnectionStr)));
services.AddControllers();
Now it will resolve your issue.
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.