I am creating a cascading dropdown and receiving the error CREATE FILE encountered operating system error 5(Access is denied.) when the dropdown is initializing. I built a EF database first application and no files should be created. No idea why it would be trying to create any files.
My cascading dropdowns are a Manufacturer dropdown that when selected another dropdown is loaded with corresponding Models.
the ViewModel that created -
public class ManufacturerModelContext : DbContext
{
public DbSet<Manufacturer> Manufacturers { get; set; }
public DbSet<ManufacturerModel> ManufacturerModels { get; set; }
}
I populate the dropdowns with -
//Populate the cascading dropdowns for manufacturer and model
ManufacturerModelContext mm = new ManufacturerModelContext();
[HttpGet]
public JsonResult GetManufacturers()
{
var manufacturer = from a in mm.Manufacturers
select a.Manufacturer1;
return Json(manufacturer.ToList(), JsonRequestBehavior.AllowGet);
}
public JsonResult GetModelsByManufacturerID(string manufacturerId)
{
int Id = Convert.ToInt32(manufacturerId);
var models = from a in mm.ManufacturerModels where a.ManufacturerID == Id select a;
return Json(models);
}
my ajax code is -
$(function () {
$.ajax({
type: "GET",
url: "GetManufacturers",
datatype: "Json",
contentType: "application/json; charset=utf-8",
success: function (data) {
$.each(data, function (index, value) {
//alert("ManufacturerID: " + value.ManufacturerID + " Manufacturer: " + value.Manufacturer1);
$('#dropdownManufacturer').append('<option value="' + value.ManufacturerID + '">' +
value.Manufacturer1 + '</option>');
});
},
error: function(error){
alert("Error Ajax not working: " + error);
}
});
$('#dropdownManufacturer').change(function () {
$('#dropdownModel').empty();
$.ajax({
type: "POST",
url: "GetModelsByManufacturerID",
datatype: "Json",
data: { manufacturerID: $('#dropdownManufacturer').val() },
success: function (data) {
$.each(data, function (index, value) {
$('#dropdownModel').append('<option value="' + value.ManufacturerID + '">' +
value.Model + '</option>');
});
},
error: function (error) {
alert("Error Ajax not working: " + error);
}
});
});
});
and I populate my dropdowns with -
<div class="form-group">
@Html.LabelFor(model => model.ManufacturerModelID, "Manufacturer", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("dropdownManufacturer", new SelectList(string.Empty, "Value", "Text"), "Please select a manufacturer", new { @style = "width:250;" })
@Html.ValidationMessageFor(model => model.ManufacturerModelID)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ManufacturerModelID, "Model", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("dropdownModel", new SelectList(string.Empty, "Value", "Text"), "Please select a model", new { @style = "width:250;" })
@Html.ValidationMessageFor(model => model.ManufacturerModel.Model)
</div>
</div>
Update --
StackTrace error
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3
System.Data.SqlClient.SqlException
with the error -- "CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\\inetpub\\wwwroot\\DEQ\\AQB\\AQB_MON\\AQB_MON\\App_Data\\AQB_MON.ViewModels.ManufacturerModelContext.mdf'.\r\nCREATE DATABASE failed. Some file names listed could not be created. Check related errors."} ---- There is no ManufacturerModelContext.mdf unless this has something due to me defining my ViewModel as a DbContext