D:\Program Files\Microsoft SQL Server\MSSQL10_50.R2\MSSQL\DATA
Step 2. In VS, configure the connection string in the web.config file as below:
<configuration>
<connectionStrings>
<add name="myconnectionstring" connectionString="Server=MachineName\InstanceName;
Database=SmallBakery4;User
ID=YourWindowsLogin;Password=YourWindowsPW;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true">
</compilation>
</system.web>
Step 3. In VS, in the cshtml file, use Database.Open('myconnectionstringname') to open the database:
@{
//var db
= Database.Open("SmallBakery"); use this option if using compact
edition in WebMatrix
var db = Database.Open("myconnectionstring"); //defined in the web.confog
file
var query = "SELECT *
FROM Product";
}
<html>
<body>
<h1>Small Bakery Products</h1>
<table border="1" width="70%">
<tr>
<th>Id</th>
<th>Product</th>
<th>Description</th>
<th>Price</th>
</tr>
@foreach (var row in db.Query(query))
{
<tr>
<td>@row.Id</td>
<td>@row.Name</td>
<td>@row.Description</td>
<td align="right">@row.Price</td>
</tr>
}
</table>
</body>
</html>
Step 5. Also notice, there is no database file in the C:\Users\Charlie\Documents\Visual Studio 2012\WebSites\WebSite1\App_Data folder,neither in the App_Data folder in VS (The two should represent the same information).