1

I'm starting a new project and intend to use a local database file during development, rather than using a network server. I can query it by right clicking on the .mdf in Server Explorer and selecting New Query, but that's going to be a pain in the neck to have to copy all of my sql scripts over to it on a regular basis.

I apologize if my post is ambiguous - I'm having a hard time wording what I want to do. I want to use the SQL Server prompt with the .mdf file in my App_Data. (screenshot)

When I check the connection string of the .mdf in Server Explorer, I get the following:

Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\[username]\Desktop\...\App_Data\localdb.mdf;Integrated Security=True

I've not managed to get this string, in any form, to work, though.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
wmaynard
  • 238
  • 1
  • 3
  • 12
  • I'm not sure if you'll be able to connect to a local MDF file without a proper SQL Server running. Have you considered installing [SQL Server Express](http://www.microsoft.com/en-us/server-cloud/Products/sql-server-editions/sql-server-express.aspx#fbid=fyNKe8pJZ5k) on your dev PC? – Andy May 09 '14 at 19:28
  • Try looking at [this MSDN article](http://msdn.microsoft.com/en-us/library/ms171890.aspx) – Icemanind May 09 '14 at 19:30
  • I've got Sql Server installed on one machine, but not on the other 3 machines that this will project will be developed on. I would use a network database if my connection wasn't blocked by firewalls on two machines, and I don't have administrative rights on one. Not the biggest deal in the world, but it's inconvenient if this won't work out. – wmaynard May 09 '14 at 19:31
  • @sflancer06 Try to attach the file to Sql Server. In **Sql Management Studio** right click in *Databases* folder then *Attach* Menu. – rareyesdev May 09 '14 at 19:37

1 Answers1

3

Ran into this same issue and was getting annoyed. Solution ended up being quite simple. This is the connection string generated by Entity Framework:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\******.mdf;Initial Catalog=******;Integrated Security=True" providerName="System.Data.SqlClient" />

Simply grab the data source and plug that into the "Server name:" in SQL Server Management Studio:

enter image description here

Good to go!

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
  • Note by the way [what's the issue with AttachDbFilename](https://stackoverflow.com/questions/11178720/whats-the-issue-with-attachdbfilename) – Charlieface Jul 05 '22 at 23:30