I have tried everything but I am having trouble getting a basic asp.net site to connect to a database. I'm using Visual Studio and trying to retrieve data from a local database file into a table on a .cshtml page.
The database I am trying to access is in the App_Data folder.
On the Web.config file I have the following under connection strings:
<add name="connectionName" connectionString="Data Source=|DataDirectory|\database.mdf" providerName="System.Data.SqlClient"/>
On the page itself I have:
@{
var DB = Database.Open("connectionName");
var selectQueryString = "SELECT * FROM Clients ORDER BY lastName";
}
<table>
<thead>
<tr>
<td>client_id</td>
<td>firstName</td>
<td>lastName</td>
<td>address</td>
<td>city</td>
<td>state</td>
<td>postalCode</td>
<td>phone</td>
</tr>
</thead>
@foreach (var row in DB.Query(selectQueryString))
{
<tr>
<td>@row.client_id</td>
<td>@row.firstName</td>
<td>@row.lastName</td>
<td>@row.address</td>
<td>@row.city</td>
<td>@row.state</td>
<td>@row.postalCode</td>
<td>@row.phone</td>
</tr>
}
</table>
The exception that is being thrown is:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
I am also seeing some text stating that the issues may be:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)