Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';t使用Visual Studio 2013在SQL Server 2014中插入或删除记录_C#_Sql Server_Visual Studio 2013_Ado.net Entity Data Model - Fatal编程技术网

C# Can';t使用Visual Studio 2013在SQL Server 2014中插入或删除记录

C# Can';t使用Visual Studio 2013在SQL Server 2014中插入或删除记录,c#,sql-server,visual-studio-2013,ado.net-entity-data-model,C#,Sql Server,Visual Studio 2013,Ado.net Entity Data Model,上下文 我使用的是Visual Studio 2013,我创建了一个ADO.Net实体数据模型,该模型连接到我的SQL Server 2014数据库 我可以使用RESTful服务检索并显示数据 问题 但是我不能在任何表中插入数据(也不能删除和编辑) 我的连接是否设置为只读模式?我查看了数据库的属性,但没有任何内容指向该选项 有人帮忙吗 编辑: 这是我的WCF服务代码。下面是Create()正文: using (OnlinestoreEntities ose = new OnlinestoreEn

上下文

我使用的是Visual Studio 2013,我创建了一个ADO.Net实体数据模型,该模型连接到我的SQL Server 2014数据库

我可以使用RESTful服务检索并显示数据

问题

但是我不能在任何表中插入数据(也不能删除和编辑)

我的连接是否设置为只读模式?我查看了数据库的属性,但没有任何内容指向该选项

有人帮忙吗

编辑:

这是我的WCF服务代码。下面是
Create()
正文:

using (OnlinestoreEntities ose = new OnlinestoreEntities())
{
    try
    {
        UserEntity user = new UserEntity();
        user.Id = _user.Id;
        user.Name = _user.Name;
        user.Password = _user.Password;
        user.Email = _user.Email;

        ose.UserEntities.Add(user);
        ose.SaveChanges();

        return true;
    }
    catch
    {
        return false;
    }
};
以下代码是客户端的
Create()
(使用MVS模型),单击
adduser
链接时从控制器调用此函数:

public bool Create(User user)
{
    try
    {
        var webClient = new WebClient();
        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));

        MemoryStream mem = new MemoryStream();
        ser.WriteObject(mem, user);

        string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);

        webClient.Headers["Content-type"] = "application/json";
        webClient.Encoding = Encoding.UTF8;

        String str = webClient.UploadString(BASE_URL + "create", "POST", data);
        return true;
    }
    catch
    {
        return false;
    }
}

你还需要任何细节吗,我以为问题是关于DB设置的

看起来您用于连接SQL数据库的用户名具有只读访问权限。您应该使用其他具有DML操作权限的用户名

如果您没有其他用户名,则必须联系SQL server的DBA

编辑

安装SQL server时,您将获得一个选项,用于配置如何对SQL server进行身份验证(即Windows身份验证模式或混合模式)。我喜欢混合模式

选择混合模式后,您必须配置“SA”密码

对我来说,它看起来像你在使用windows身份验证,只有你有管理员权限,其他人都配置为只读


在IIS中部署ASP.Net应用程序时。默认情况下,需要AppPoolIdentity打开SQL连接,而SQL连接没有执行DML操作的任何权限

如果您没有向我们展示任何内容,我们可能无法回答您的问题!向我们显示您的连接字符串,向我们显示您用于尝试插入或删除数据的代码。毕竟,我们看不到你的屏幕,也看不懂你的心思!完成!!这是不是更好呢?比如,我会尝试捕捉异常中发生的情况,而不是“无声地”返回false。如果出现问题-异常(以及可能出现的
.InnerException
)会告诉您出了什么问题-您需要知道这些信息!这就是我所说的,实际上我是DBA,这是一个本地项目,在安装SQL Server时是否有任何选项使我处于只读模式。或者在连接时。我正在使用windows身份验证,这有关系吗?在DB属性中,在权限点击下:有用户或角色。我已经添加了来宾和公共用户,并授予他们删除/插入/编辑的所有权限。但是没有改变?好的,我会重新安装SQL Server,谢谢你的帮助,谢谢!谢谢你的回答,这是一个许可的问题。当我以管理员的身份运行VisualStudio时,它工作得很好。至少我知道问题不在我的代码中。