首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建文件遇到操作系统错误5(访问被拒绝)。

创建文件遇到操作系统错误5(访问被拒绝)。
EN

Stack Overflow用户
提问于 2016-08-25 20:28:23
回答 1查看 2K关注 0票数 0

我正在创建一个级联下拉列表,并接收错误创建文件,遇到操作系统错误5(访问被拒绝。)时,下拉列表正在初始化。我首先构建了EF数据库应用程序,不应该创建任何文件。不知道它为什么要创建任何文件。

我的级联下降是一个制造商下拉,当选择另一个下拉是装载了相应的模型。

ViewModel创造了-

代码语言:javascript
复制
public class ManufacturerModelContext : DbContext
{

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

我用-

代码语言:javascript
复制
//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代码是-

代码语言:javascript
复制
 $(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);
            }
        });
    });
});

我用-

代码语言:javascript
复制
    <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>

更新

StackTrace错误

代码语言:javascript
复制
   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 
EN

回答 1

Stack Overflow用户

发布于 2016-08-26 07:55:27

您的sql server数据库可能没有创建mdf数据库文件的权限,您可以尝试运行您作为管理员使用的软件,或者检查该文件/目录的权限。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39154226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档