entity framework - Unable to initialize database -
i unable iniitialize database. steps simple explained here. here. error not explainatory guess something wrong around connection string
couldn't figured out. can please see me.
error
" @ system.data.common.dbconnectionoptions.getkeyvaluepair(string connectionstring, int32 currentposition, stringbuilder buffer, string& keyname, string& keyvalue)\r\n
at system.data.common.dbconnectionoptions.parseinternal(dictionary
2 parsetable, string connectionstring, boolean buildchain, dictionary
2 synonyms)\r\n t system.data.common.dbconnectionoptions..ctor(string connectionstring, dictionary2 synonyms)\r\n @ system.data.sqlclient.sqlconnectionstring..ctor(string connectionstring)\r\n @ system.data.sqlclient.sqlconnectionfactory.createconnectionoptions(string connectionstring, dbconnectionoptions previous)\r\n @ system.data.providerbase.dbconnectionfactory.getconnectionpoolgroup(dbconnectionpoolkey key, dbconnectionpoolgroupoptions pooloptions, dbconnectionoptions& userconnectionoptions)\r\n @ system.data.sqlclient.sqlconnection.connectionstring_set(dbconnectionpoolkey key)\r\n @ system.data.sqlclient.sqlconnection.set_connectionstring(string value)\r\n @ system.data.sqlclient.sqlconnection..ctor(string connectionstring)\r\n @ microsoft.entityframeworkcore.storage.internal.sqlserverconnection.createdbconnection()\r\n @ microsoft.entityframeworkcore.internal.lazyref
1.get_value()\r\n
@ microsoft.entityframeworkcore.storage.relationalconnection.open(boolean errorsexpected)\r\n @ microsoft.entityframeworkcore.storage.internal.sqlserverdatabasecreator.<>c__displayclass18_0.b__0(datetime giveup)\r\n @ microsoft.entityframeworkcore.executionstrategyextensions.<>c__displayclass12_02.<execute>b__0(dbcontext c, tstate s)\r\n @ microsoft.entityframeworkcore.storage.internal.sqlserverexecutionstrategy.execute[tstate,tresult](tstate state, func
3 operation, func3 verifysucceeded)\r\n @ microsoft.entityframeworkcore.executionstrategyextensions.execute[tstate,tresult](iexecutionstrategy strategy, func
2 operation, func2 verifysucceeded, tstate state)\r\n t microsoft.entityframeworkcore.executionstrategyextensions.execute[tstate,tresult](iexecutionstrategy strategy, tstate state, func
2 operation)\r\n @ microsoft.entityframeworkcore.storage.internal.sqlserverdatabasecreator.exists(boolean retryonnotexists)\r\n @ microsoft.entityframeworkcore.storage.internal.sqlserverdatabasecreator.exists()\r\n @ microsoft.entityframeworkcore.storage.relationaldatabasecreator.ensurecreated()\r\n @ microsoft.entityframeworkcore.infrastructure.databasefacade.ensurecreated()\r\n @ ifs.toolsuite.dataaccess.dbinitializer.initialize(toolsuitecontext context) in c:...........\dbinitializer.cs:line 12\r\n @ ifs.toolsuite.startup.program.main(string[] args) in c:\......startup\program.cs:line 27"
program.cs
public static void main(string[] args) { var host = buildwebhost(args); using (var scope = host.services.createscope()) { var services = scope.serviceprovider; try { var context = services.getrequiredservice<testcontext>(); dbinitializer.initialize(context); } catch (exception ex) { var logger = services.getrequiredservice<ilogger<program>>(); logger.logerror(ex, "an error occurred while seeding database."); } } host.run(); } public static iwebhost buildwebhost(string[] args) => webhost.createdefaultbuilder(args) .usestartup<startup>() .build();
startup.cs
public void configureservices(iservicecollection services) { // add framework services. services.adddbcontext<testcontext>(options => options.usesqlserver(configuration.getconnectionstring("applicationdb"))); services.addmvc(); }
dbintitializer.cs
public static class dbinitializer { public static void initialize (testcontext context) { context.database.ensurecreated(); devcoredataseed.initialize(); } } appsettings.json { "connectionstrings": { "applicationdb": "server=.\\sqlexpress;database=testdb;trusted_connection=true;multipleactiveresultsets=true" }, "logging": { "includescopes": false, "debug": { "loglevel": { "default": "warning" } }, "console": { "loglevel": { "default": "warning" } } } }
Comments
Post a Comment