Avatar of Eamon
Flag for Ireland asked on

sql connection file or database

I just need something cleared up.
In web pages can connect to a sqlserver database, i do this all the time and have now problem with that.
you can also connect to the .mdf file. This is where i am confused. can you connect to the mdf file in the same way you would connect to a access(mdb) file or do you still need sql server running on the machine where the mdf is.
I am not really looking for a connection string, I'm looking for a clear explaination of what is going on and the reasons or different uses for this.

example below
        <add name="SqlExpressConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\data.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
            providerName="System.Data.SqlClient" />

ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

Databases use different types of Providers:  I. E.  sqloedb, obdc, etc...and the connection string contains the information that the provider need to know to be able to establish a connection to the database or the data file.  

And no, Access does not use SqlServer, it uses a database server embedded by microsoft

But what is the difference between this which is connecting to a sql server instance
and the first connection that was connecting to the database file (.mdf)

  <add name="MyConnectionString" connectionString="Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True"
   providerName="System.Data.SqlClient" />

And why would you use the file(mdf) connection and if you do use it do you need SqlServer running

With Visual Studio 2005 you get a cut down version of SQL Server software called SQL Server Express. This allows you to create a database as a file and use all the same functions that a proper SQL database would use. My understanding is this could be used for very simple applications on your PC and for testing but wouldn't really be used in a full online application. I guess a small online app would work but it wouldn't really scale very well.

A full SQL server instalation is designed to be scalable and could even span multiple drives, servers etc.

Within my application I have 2 connection strings depending on if i'm want to debug the live sql server or the debug version which is on my PC. I just comment one out and leave other in and then swap around when i want to change. This works for me.

Hope this helps.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

But still when testing why not use sql express and connect to the database. Why connect to the file as apposed to the server.
I am sorry for being thick but I am just not getting it.

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.