Prevent update of MDF file when attaching to newer version of LocalDb

c# entity-framework-6 localdb sql-server winforms

Question

I have WinForms app using EF6. The app use LocalDb storage (2014) because I need it to work from Windows 7 to the Windows 10.

And it is delivered with a .mdf file in app folder, and attaching it via connection string.

When I attach the .mdf file (created in SQL Server 2014 Express) to a newer versions of SQL Server Express, the .mdf is upgraded and I can't port it back to the Windows 7 anymore. That prevents me to develop app on multiple machines, because I can't make release copy of app with that .mdf, because it won't work on Windows 7 anymore.

Only way is to use SQL Server 2014 Express on all developer machines.

Is there way in connection string to prevent upgrade or that is needed for .mdf file to work on newer versions of SQL Server Express?

I'm thinking now to make .mdf file programmatically on first app start and execute script to make tables and seed data, and then attach that file. And I don't need to think what LocalDb version is used on that machine.

1
0
3/13/2020 3:15:11 PM

Accepted Answer

No - you CANNOT prevent or exclude the .mdf from being upgraded to the current internal database version when attaching to a newer server instance.

You need to either use the same version of SQL Server (Express / LocalDB) on all machines involved in the development - or you need to upgrade your existing database structure (and possibly static lookup data) by means of SQL scripts or Entity Framework migrations (or a similar, comparable mechanism that doesn't rely on internal SQL Server database versions).

0
3/13/2020 3:16:50 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow