CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Skip Navigation LinksHome » FAQs » What is the connection string when you use SQL express database in App_Data in ASP.Net ?   You are not logged in.
Search
 

Technologies
 

What is the connection string when you use SQL express database in App_Data in ASP.Net ?
Submitted By Satheesh Babu B
On 3/11/2010 8:27:23 AM
Tags: Interview Questions,SQL Express  

What is the connection string when you use SQL express database in App_Data in ASP.Net ?

 

With Visual studio 2005, Microsoft released a new version of SQL server called called SQLExpress. This is compact database that gets installed when installing visual studio 2005 and above. The SQLExpress database allows us to create a database(as .mdf file) in our visual studio solution under App_Data folder.

We can use the below connection string in web.config file to connect a SQL express database created in the App_Data folder of your visual studio 2005 or 2008.
The Database.mdf is the database file name, you can change it accordingly with the database file name you have created.

 

<connectionStrings>
  <add name="Sql" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;"/>
 </connectionStrings>

 

The |DataDirectory| will actually return the path the .mdf file in your solution explorer. Hence, you need not configure the AttachDbFilename property with the actual path of the database(.mdf) directory. This also prevent us from updating the database location when we move the project to different location or different server, etc.

Happy Coding!!

Recent FAQs
  • View All FAQs..