我想從VS2013中的網頁訪問數據庫。它給我的錯誤從網頁訪問數據庫時出錯
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: 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)"
我的代碼:
@{
var db = Database.Open("Rohit");
var selectQueryString = "SELECT * FROM Sample";
}
<html>
<body>
<h1>Small Bakery Products</h1>
<table>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
@foreach (var row in db.Query(selectQueryString))
{
<tr>
<td>@row.Id</td>
<td>@row.Name</td>
</tr>
}
</table>
這是給錯誤的@foreach
線。
錯誤在行 - @foreach(var.db.Query(selectQueryString)中的行)。因此,我認爲連接數據庫沒有問題 – user2095748
請確保您在AppCode文件夾中具有'.mdf'文件並且'Web.config'中具有'ConnectionString' – mmushtaq
我可以在App_Data文件夾中找到我的數據庫。但是web.config中不存在相對連接字符串。 – user2095748