Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

enter image description here

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 ?

like image 422
IronSlug Avatar asked Dec 19 '14 10:12

IronSlug


1 Answers

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

like image 111
Mikhail Lobanov Avatar answered Oct 26 '22 09:10

Mikhail Lobanov