Posts Tagged ‘sql express’

Using SQL Express Databases

January 18th, 2010

If you use a SQL Express database for LINQ to SQL in an MVC application Studio will create an App_Data directory and put the database there. However, when you copy your solution up to a web host you might get connection problems. This is likely to be because the LINQ designer has embedded a path to the database that isn’t valid on the server.
The fix is really simple – just use the |DataDirectory| keyword in your Web.config.

<connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
Share