I am building an application using .NET5, and I am trying to use the EF Core update-migrations and I get the following error:
Format of the initialization string does not conform to specification starting at index 0.
By viewing similar posts, I figured my connectionstring
is the problem. However I cant seem to find the correct string to use. If I look at the properties of my localDB it says its connectionstring
is:
Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
I set it to be DefaultConnection appsettings.json
and connect like this in startup.cs
services.AddDbContext<AppDbContext>(options => options.UseSqlServer("DefaultConnection"));
Any ideas would be greatly appreciated.
Thank you.
EDIT:
Went trough uninstalling SQL Express first, for then to be given this string after installation:
Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;
After installing localDB again I fixed the issue by modifying the connectionstring to:
Server=(localdb)\\MSSQLLocalDB;Database=master;Trusted_Connection=True;
3条答案
按热度按时间2mbi3lxu1#
.UseSqlServer(string) expects a connection string, not the name of a configuration parameter.
So you must fetch the connection string from your configuration and pass it to
.UseSqlServer
. For instance in ASP.NET there's a Startup class with an IConfiguration instance you can use. EGwz1wpwve2#
Sometimes your start project is on multiple projects. be sure just a main project is started. after building the project, you can select some projects to start again. enter image description here
lnlaulya3#
I've got that error because of some programming mistake I made in the
Data/MyAppDbContext.cs
In my case, modifying the code into the following one made that error go away.