0

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 
10
  • Please provide the stack trace.
    – user47589
    Aug 25, 2016 at 20:30
  • Without the entire exception details we can't help you. All we can do is guess, like the application pool user account does not have rights to create your database.
    – user1228
    Aug 25, 2016 at 20:40
  • Stupid question however where would I find stack trace? Aug 25, 2016 at 20:41
  • The entire error I receive is an 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 Aug 25, 2016 at 20:46
  • Okay then, how is your db configured in your web.config? It's attempting to create the database but doesn't have permissions.
    – user47589
    Aug 25, 2016 at 20:51

1 Answer 1

1

perhaps your sql server database is not running with permission to create that mdf database file you can try running the software you are using as administrator or check permissions on that file/directories

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.