In Sql Server 2008 R2 database files you can connect with
Server=np:\\.\pipe\YourInstance\tsql\query;InitialCatalog=yourDataBase;Trusted_Connection=True;
only, but in sql Server 2012 you can use this:
Server=(localdb)\v11.0;Integrated Security=true;Database=DB1;
and it depended on your .mdf
.ldf
version.
for finding programmicaly i use this Method that explained in this post