I have a C# ASP.NET MVC application that connects to a local mdf database file in the same folder using this in web.config
:
<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>
and this:
@{
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>
I get this error:
[SqlException (0x80131904): Cannot attach file 'C:\\Users\\Chase\\Desktop\\DDAC Assignment\\DDAC Assignment - CMS\\CMS Databases\\N.US.mdf' as database 'NUS, Integrated Security=true' because this file is already in use for database 'N.US,Container ID=containerid,Warehouse ID=WarehouseID,Imported From=IF']
This has being troubling me for the past couple of days. Sorry I am new to this, but could you please give me some advise on how to solve this? I would really appreciate it. I just want to connect to the .mdf
database file.
Using WebMatrix , You may take a look at the tutorials available on the asp.net site.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.