我有一个C#ASP.NET MVC应用程序,在web.config
中使用它连接到同一文件夹中的本地mdf数据库文件:
<connectionStrings>
<add name="ImportNUS"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFileName=C:\Users\Chase\Desktop\DDAC Assignment\DDAC Assignment - CMS\CMS Databases\N.US.mdf;Initial Catalog=NUS, Integrated Security=true;"
providerName="System.Data.SqlClient" />
</connectionStrings>
和此:
@{
var DB = Database.Open("ImportNUS");
var selectQueryString = "SELECT * FROM IMPORT ORDER by Customer ID";}
<div id="Import" class="tab-pane fade">
<h3>Import</h3>
<table>
<thead>
<tr>
<th>Id</th>
<th>Product</th>
<th>Description</th>
</tr>
</thead>
@foreach(var row in DB.Query(selectQueryString)){
<tr>
<td>@row.Container ID</td>
<td>@row.Warehouse ID</td>
<td>@row.Imported From</td>
</tr>
}
}
}
</table>
</div>
我收到此错误:
[SqlException(0x80131904):无法附加文件&#39; C:\ Users \ Chase \ Desktop \ DDAC Assignment \ DDAC Assignment - CMS \ CMS Databases \ N.US.mdf&#39;作为数据库&#39; NUS,Integrated Security = true&#39;因为此文件已用于数据库&n; N.US,Container ID = containerid,仓库ID = WarehouseID,导入自= IF&#39;]
这让我在过去几天感到不安。对不起,我是新手,但是请你就如何解决这个问题给我一些建议?我真的很感激。我只想连接到.mdf
数据库文件。