SQL 2014 LocalDB: Instance “v12.0” není automaticky založena (50 – Local Database Runtime error occurred. The specified LocalDB instance does not exist.)

Mám na počítači čerstvou instalaci SQL Serveru 2014 (včetně LocalDB) a hraju si s Entity Frameworkem 6.1.0, Výchozí konektivitou je “(localdb)\v12.0” a dostávám krásnou chybu:

System.Data.Entity.Core.ProviderIncompatibleException, but exception System.Data.Entity.Validation.DbEntityValidationException was expected. Exception message: System.Data.Entity.Core.ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application’s config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure. —> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. —> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 – Local Database Runtime error occurred. The specified LocalDB instance does not exist.)

Po chvilce bojů zjišťuji, že SQL Server 2014 LocalDB má v sobě ?bug?, a to že nezaloží automaticky instanci “v12.0”, ač to o sobě v dokumentaci tvrdí a EntityFramework to očekává: https://connect.microsoft.com/SQLServer/feedback/details/845278/sql-server-2014-express-localdb-does-not-create-automatic-instance-v12-0

Řešení je naštěstí poměrně snadné, z Command Promptu stačí instanci vytvořit:

sqllocaldb create v12.0 12.0

…a hrátky s Entity Frameworkem mohou pokračovat. ;-)

Update: Test/Build Server

Pozor, že na test/build serveru, kde se budou pouštět unit-testy, je potřeba instanci založit pod účtem, který testy pouští. Instance LocalDB nejsou sdíleny mezi účty, není-li explicitně nastaveno jinak (a pozor, že prostý „sqllocaldb share v12.0 v12.0“ ve skutečnosti nasdílí instanci pod názvem „.\v12.0“, nikoliv „v12.0“).

Napsat komentář