Hi,
I am developing an ASP.NET 6 website with VS2022 that includes Identity and I am trying to create the Indentity Tables. The project has 2 contexts for 2 different DBs. I already successfully ran the add-migration command for each context but I am getting an error when issuing the update-database command.
The add-migration command for each context was run as follows:
- add-migration -Name CreateIdentitySchema -OutptDir Data\Migrations\Elisur -Context ElisurDbContext
- add-migration -Name CreateIdentitySchema -OutptDir Data\Migrations\RioPoderoso -Context RioPoderosoDbContext
Both commands ran correctly.
I am trying to run the first update-database command on the ElisurDbContext context as follows:
- update-database -Connection ElisurConnection -Context ElisurDbContext
But I get an error that starts as follows:
Entity Framework Core 6.0.2 initialized 'ElisurDbContext' using provider 'Devart.Data.PostgreSql.Entity.EFCore:(null)' with options: None
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)
I already searched for a solution in the web and what I have found is that basically the problem resides in the connection string but my connection strings are correct (I have review them several times). This is the content of the ConnectionStrings section in the appsettings.json file:
{
"ConnectionStrings": {
"DefaultConnection": "host=localhost; database=elisur; schema=elisur; port=5434; user id=postgres; password=pass01; License Key=n7UBDBU7VZ2bJ2bnpFvq0WiQliEDxJRPtvByFjBXw5SwmZj1oyZg+lVDiR7b0/sTC5EZOf4dUDtrzLJj/RxA+fkRIgcDTtyc3t4oI0il+q//ek8QqTzeIicZUQo2xm0fZdfDk4mYSqxdlesin3VxZ5BR/HLsWzAdukPypvM52xrf0mbVczcWoyEfwah4lb/q/1SZnvgccHWhcIY+IWAXxutlmm1Hg/8aW5hMUUK3HF5gsHzR/YcXz54GGmiq2/E9LSiIZya+Lwv4VboCCP2mI9ZMZ23/GzHd4jGykCqdOnE=",
"ElisurConnection": "host=localhost; database=elisur; schema=elisur; port=5434; user id=postgres; password=pass01; License Key=n7UBDBU7VZ2bJ2bnpFvq0WiQliEDxJRPtvByFjBXw5SwmZj1oyZg+lVDiR7b0/sTC5EZOf4dUDtrzLJj/RxA+fkRIgcDTtyc3t4oI0il+q//ek8QqTzeIicZUQo2xm0fZdfDk4mYSqxdlesin3VxZ5BR/HLsWzAdukPypvM52xrf0mbVczcWoyEfwah4lb/q/1SZnvgccHWhcIY+IWAXxutlmm1Hg/8aW5hMUUK3HF5gsHzR/YcXz54GGmiq2/E9LSiIZya+Lwv4VboCCP2mI9ZMZ23/GzHd4jGykCqdOnE=",
"RioPoderosoConnection": "host=localhost; database=riopoderoso; schema=riopoderoso; port=5434; user id=postgres; password=pas001; License Key=n7UBDBU7VZ2bJ2bnpFvq0WiQliEDxJRPtvByFjBXw5SwmZj1oyZg+lVDiR7b0/sTC5EZOf4dUDtrzLJj/RxA+fkRIgcDTtyc3t4oI0il+q//ek8QqTzeIicZUQo2xm0fZdfDk4mYSqxdlesin3VxZ5BR/HLsWzAdukPypvM52xrf0mbVczcWoyEfwah4lb/q/1SZnvgccHWhcIY+IWAXxutlmm1Hg/8aW5hMUUK3HF5gsHzR/YcXz54GGmiq2/E9LSiIZya+Lwv4VboCCP2mI9ZMZ23/GzHd4jGykCqdOnE=",
"SQLConnection": "Server=tcp:409951.database.windows.net,1433;Initial Catalog=SDT;Persist Security Info=False;User ID=sensei;Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}
Connection strings have a parameter called License Key which is required by the ADO.NET Data Provider I use which is dotConnect for PostgreSQL.
Database and schema already exist and the DB engine service is running in port 5434.
Also, the program.cs contains the following code. Although there exists a ApplicationDbContext, it is not used for now.
builder.Services.
AddDbContext<ApplicationDbContext>(opts1 => opts1.UsePostgreSql(builder.Configuration.GetConnectionString("DefaultConnection"))).
AddDbContext<RioPoderosoDbContext>(opts2 => opts2.UsePostgreSql(builder.Configuration.GetConnectionString("RioPoderosoConnection"))).
AddDbContext<ElisurDbContext>(opts3 => opts3.UsePostgreSql(builder.Configuration.GetConnectionString("ElisurConnection")));
builder.Services.AddIdentity<IdentityUser, IdentityRole>(
options => {
options.SignIn.RequireConfirmedAccount = true;
options.SignIn.RequireConfirmedEmail = true;
//Other options go here
}
)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddEntityFrameworkStores<ElisurDbContext>()
.AddEntityFrameworkStores<RioPoderosoDbContext>()
.AddDefaultTokenProviders();
I will very much appreciate your feedback as I have been struggling with this issue for some days.
With respect,
Jorge Maldonado