What is the best way to attach existing database to sql localdb?

烂漫一生 提交于 2019-12-05 18:22:49

问题


Context

I'm working on a desktop app which must be able to run in case of connection loss with the distant sql server : a SQL Server Express (I know...) 2012. I'm working on Visual Studio Express 2013. So I figured out that my best option is to use SQLLocalDB as my client local DB as I just have to import my data-free mdf file and handle the data synch (which represent a quite simple enough ruleset) by myself. To attach the mdf file to SQLLocalDB, I have two options but I do not understand clearly the consequences of each one.

Solution 1 - Transact SQL

Solution 2 - Connexion string

"Server=(localdb)\\v11.0;Integrated Security=true;AttachDbFileName= myDbFile.mdf;"

What is the best way to go knowing that I use Entity Framework to access the data in code ?


回答1:


My opinion is solution #2 is better because it's based on connection string to databse.

In SQL Express you can specify a db name in T-SQL too (USE DB_NAME). But people usually specify db in a connection string rather than T-SQL



来源:https://stackoverflow.com/questions/27564279/what-is-the-best-way-to-attach-existing-database-to-sql-localdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!