.net - EF 4.3+ connection string initiation -
i creating exemplary simple application uses code first ef migrations. have context object creates database if 1 doesn't exist yet using defaultconnectionfactory. wondering how can overwrite these settings, hold command on databse name. when commented out defaultconnectionfactory , set connection string still same old database name. why?
<?xml version="1.0" encoding="utf-8"?> <configuration> <configsections> <!-- more info on entity framework configuration, visit http://go.microsoft.com/fwlink/?linkid=237468 --> <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=5.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> </configsections> <!--<entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.sqlconnectionfactory, entityframework" /> </entityframework>--> <connectionstrings> <add name="migrationsdemoconnection" connectionstring="data source=.\sqlexpress;initial catalog=migrationsdemo;integrated security=true" providername="system.data.sqlclient" /> </connectionstrings> </configuration>
the database name in connection string. assume context has constructor taking "migrationsdemoconnection" argument. uses database name "migrationsdemo". connection string place alter database name.
you can build context total connection string argument. can take connection string config file , alter database name, preferably using sqlconnectionstringbuilder.
.net entity-framework database-connection
No comments:
Post a Comment