I use to attach a database to my server explorer in visual studio 2010, instead of using a connection to sql server 2008 which i have installed on my pc.
Example:
My connection string used to be this:
<add name="YourGuruDB"
connectionString="Data Source=DIMA-00AA1DA557;Initial Catalog=model;Integrated Security=True"/>
And now it has changed to this:
<add name="YourGuruDB"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\Little Rabbit\Desktop\New Folder (2)\YourGuruDB1.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient"/>
Is there a difference in the way I choose to connect a database (on performance or security or comfort, for example)?
Your first connection string is using SQL Server (Express or other edition) as a server – the server is running the whole time, your clients are just connecting to it using a symbolic name (for the server and the database).
In your second example, you’re limited to the SQL Server Express editions – this approach doesn’t work with any other edition. Also: you’re “spinning up and attaching” a SQL Server Express instance when you connect —> sounds like this might take up quite some time, at least during the first hit. And also: now your clients suddenly have to deal with presence of .MDF files and stuff like that…..
Personally, I would always use the server-based approach – or if you really need a database on a local client machine, use SQL Server Compact Edition (using a single
.sdffile) instead.