Format of the initialization string does not conform to specification starting at index 0 when using postgresql database in .net 6 app
NickName:dros Ask DateTime:2022-08-01T02:05:15

Format of the initialization string does not conform to specification starting at index 0 when using postgresql database in .net 6 app

trying to update my database via dotnet ef database update, however the build starts and succeeds and then errors out with the following:

    System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
   at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
   at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
   at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms, Boolean useOdbcRules)
   at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
   at Npgsql.NpgsqlConnectionStringBuilder..ctor(String connectionString)
   at Npgsql.NpgsqlConnection.GetPoolAndSettings()
   at Npgsql.NpgsqlConnection.set_ConnectionString(String value)
   at Npgsql.NpgsqlConnection..ctor(String connectionString)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlRelationalConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   at Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggerExtensions.MigrateUsingConnection(IDiagnosticsLogger`1 diagnostics, IMigrator migrator, IRelationalConnection connection)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Format of the initialization string does not conform to specification starting at index 0.

worth mentioning that my appsettings.json is in the api solution, and my dbcontext file is in my data access layer

appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "prattleDatabase": "Host=localhost; Database=prattle; Username=develop; Password=develop123;"
  }
}

programs.cs

builder.Services.AddDbContext <PrattleContext> (option =>
    option.UseNpgsql(builder.Configuration.GetConnectionString("prattleDatabase")));

and my dbcontext:

   public class PrattleContext : DbContext 
    {
        protected readonly IConfiguration _configuration;

        public PrattleContext()
        {

        }

        public PrattleContext(IConfiguration configuration)
        {
            _configuration = configuration;
        }


        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

            var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            var dbConnectionInfo = builder.Build().GetSection("ConnectionStrings").GetSection("prattleDatabase").Value;

            optionsBuilder.UseNpgsql("dbConnectionInfo");

        }

        public DbSet<User> Users { get; set; }

        public DbSet<Message> Messages { get; set; }
    }

Copyright Notice:Content Author:「dros」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73185765/format-of-the-initialization-string-does-not-conform-to-specification-starting-a

More about “Format of the initialization string does not conform to specification starting at index 0 when using postgresql database in .net 6 app” related questions

Format of the initialization string does not conform to specification starting at index 0

I have an ASP.NET application which runs fine on my local development machine. When I run this application online, it shows the following error: Format of the initialization string does not confor...

Show Detail

Format of the initialization string does not conform to specification starting at index 103

My ASP.Net application runs fine locally, but as soon as I deploy to Azure App Services it gives this error: Format of the initialization string does not conform to specification starting at index ...

Show Detail

Format of the initialization string does not conform to specification starting at index 0 when using postgresql database in .net 6 app

trying to update my database via dotnet ef database update, however the build starts and succeeds and then errors out with the following: System.ArgumentException: Format of the initialization ...

Show Detail

Format of the initialization string does not conform to specification starting at index 0

I have an ASP.Net MVC application which runs fine on my local development machine. But when deployed to IIS7 gives the following error when trying to log in: Format of the initialization string ...

Show Detail

Format of the initialization string does not conform to specification starting at index 0

I have an ASP.Net MVC application which runs fine on my local development machine. But when deployed to IIS7 gives the following error when trying to log in: Format of the initialization string ...

Show Detail

Format of the initialization string does not conform to specification starting at index 0 (update-database error)

I'm trying to create migration and I run: update-database And I get this error: Format of the initialization string does not conform to specification starting at index 0. My connection string: "

Show Detail

How to solve "Format of the initialization string does not conform to specification starting at index 0"

I'm a noob on EF and WebApi, and I've been with this problem for hours now, I searched internet and SO for the solution but any of them fixed my case. I have a simple website, using Entity Framewor...

Show Detail

Format of the initialization string does not conform to specification starting at index 0

Could any body solve my problem i am developing windows mobile 6.1 app, when i execute the application the following exception was thrown Format of the initialization string does not conform to

Show Detail

Format of the initialization string does not conform to specification starting at index 0. Unsure What This is?

I'm building a website, and I am trying to create a connection to the database. Here is the Connection code in my web.config file: &lt;add name="DBX" connectionString="Data Source=localhost;Initial

Show Detail

Format of the initialization string does not conform to specification starting at index 0. Whats wrong?

Format of the initialization string does not conform to specification starting at index 0. How to fix this error? Occurs when trying to update-database. I checked the connection string, everything is

Show Detail