将现有数据库附加到sql localdb的最佳方法是什么?

问题描述:

上下文

我正在开发一个桌面应用程序,该应用程序必须能够在与远程sql服务器的连接断开的情况下运行:SQL Server Express (我知道...)2012.我我在Visual Studio Express 2013上工作.因此,我发现最好的选择是将SQLLocalDB用作客户端本地数据库,因为我只需要导入无数据的mdf文件并处理数据同步(代表我自己一个非常简单的规则集).要将mdf文件附加到SQLLocalDB,我有两个选择,但我不清楚每个选择的后果.

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.

解决方案1-Transact SQL

解决方案2-连接字符串

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

知道我使用Entity Framework访问代码中的数据的最佳途径是什么?

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

我认为解决方案2更好,因为它基于与databse的连接字符串.

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

在SQL Express中,您也可以在T-SQL中指定一个数据库名称(USE DB_NAME).但是人们通常在连接字符串而不是T-SQL中指定db

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