entity framework - EF6 migrations (LocalDb) update-database login failed -
vs 2013 mvc5 code first project.
i’m working through asp.net getting started ef6 using mvc5 tutorial speed on latest changes , i’m having problem migrations. in first module database created using database initializer:
<contexts> <context type="contosouniversity.dal.schoolcontext, contosouniversity"> <databaseinitializer type="contosouniversity.dal.schoolinitializer, contosouniversity" /> </context> </contexts> and connection string:
<connectionstrings> <add name="schoolcontext" connectionstring="data source=(localdb)\v11.0;initial catalog=contosouniversity1;integrated security=sspi;" providername="system.data.sqlclient"/> </connectionstrings> this works fine. in code first migrations , deployment module migrations setup. initializer commented out , name of db changed contosouniversity2:
<connectionstrings> <add name="schoolcontext" connectionstring="data source=(localdb)\v11.0;initial catalog=contosouniversity2;integrated security=sspi;" providername="system.data.sqlclient"/> </connectionstrings> when update-database run packager manager console fails error message:
cannot open database "contosouniversity2" requested login. login failed. login failed user 'mymachine\myuser'. i’ve re-run both scenarios several times same user , same results. if change initial catalog attachdbfilename=|datadirectory|\contosouniversity2; update-database succeeds (the db in app-data folder of project rather root of users profile):
<connectionstrings> <add name="schoolcontext" connectionstring="data source=(localdb)\v11.0; attachdbfilename=|datadirectory|\contosouniversity2;integrated security=sspi;" providername="system.data.sqlclient"/> </connectionstrings> you have use initial catalog when deploying though. production connectionstring set separately in web.release.config workable.
the question why need fix, why doesn’t initial catalog work update-database on development side?
update 1:
the problem not migrations localdb
myuser has full rights in sqlexpress (sysadmin). can log ssms under myuser , manage dbs. ran several tests. though created initial db tutorial myuser throws login failed error if rebuild app scratch , use databaseinitialzer. if run vs under admin both databaseinitialzer , update-database work without problem. if copy dbs admin's user profile root myuser's , run vs, not admin, while logged on myuser both databaseinitialzer , update-database work if db prior existing.
if change connectionstring attachdbfilename , run either databaseinitialzer , update-database myuser can create db in app_data folder proving myuser has db create rights. myuser has full rights root of own user profile. there amisss localdb implementation.
does 1 have insight on question?
if delete db file, still stays registered sqllocaldb. if localdb gets hung can’t attach (after manually deleting db file) or login failed see jsobell’s , codingwithspike’s answers here:
ef5-cannot-attach-the-file-0-as-database-1.
run ‘sqllocaldb.exe stop v11.0’ , ‘sqllocaldb.exe delete v11.0’ pm console
update:
easier yet use ssms. server name: (local)\v11.0, windows authentication. best way manage localdb databases.
Comments
Post a Comment