2016-08-25 10 views
0

ドロップダウンを作成しているときに、エラーが発生しました。オペレーティングシステムエラー5が発生しました(アクセスは拒否されました)。私はEFデータベースの最初のアプリケーションを構築し、ファイルを作成する必要はありません。なぜそれがどんなファイルを作成しようとしているのか分かりません。ファイルの作成中にオペレーティングシステムエラー5が発生しました。(アクセスが拒否されました)

私のカスケードドロップダウンはManufacturerドロップダウンで、これを選択すると、別のドロップダウンに対応するモデルがロードされます。

作成ViewModelには -

public class ManufacturerModelContext : DbContext 
{ 

public DbSet<Manufacturer> Manufacturers { get; set; } 
public DbSet<ManufacturerModel> ManufacturerModels { get; set; } 
} 

私はドロップダウンを移入 -

//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); 
} 

私のAjaxコードがある -

$(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); 
      } 
     }); 
    }); 
}); 

と私は私のドロップダウンを移入 -

<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> 

アップデート -

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 
+0

スタックトレースを提供してください。 – Amy

+0

例外の詳細がすべてわからなければ、お手伝いできません。アプリケーションプールのユーザーアカウントにデータベースを作成する権限がないなど、われわれが推測できるのは推測だけです。 – Will

+0

愚かな質問しかし、スタックトレースはどこにありますか? –

答えて

0

は、おそらくあなたのSQL Serverデータベースは、そのMDFデータベースファイルを作成する権限で実行されていないスタックトレースエラーが あなたは、管理者またはチェックとして使用しているソフトウェアを実行してみることができますそのファイル/ディレクトリのアクセス許可

関連する問題