Home > Blockchain >  Keyword not supported: 'port' when trying to update database
Keyword not supported: 'port' when trying to update database

Time:11-05

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!

CodePudding user response:

It is supposed to be done like this:

"AuthDBContextConnection": "Server=localhost,YourPortHere;Database=xxxx;User ID = xxx;Password=xxxx;Pooling=false;SslMode=none;convert zero datetime=True;Trusted_Connection=True;MultipleActiveResultSets=true"

CodePudding user response:

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.

  • Related