无法使用 Visual Studio 2013 在 SQL Server 2014 中插入或删除记录
Can't insert or delete records in SQL Server 2014 using Visual Studio 2013
上下文
我正在使用 Visual Studio 2013,我创建了一个 ADO.Net 实体数据模型,它连接到我的 SQL Server 2014 数据库。
我可以检索我的数据并使用 RESTful 服务显示它。
问题
但我无法将数据插入任何 table(也可以删除和编辑)。
我的连接是否设置为只读模式?我查看了我的数据库的属性,但没有指向该选项。
有什么帮助吗?!
已编辑:
这是我的 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模型),当点击Add User
link时从控制器调用此函数:
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;
}
}
您还需要任何详细信息吗,我还以为是数据库设置的问题?!
看起来您用于连接 SQL 数据库的用户名具有只读访问权限。您应该使用其他有权执行 DML 操作的用户名。
如果您没有其他用户名,则必须联系 SQL 服务器的 DBA
编辑
安装 SQL 服务器时,您将获得配置选项,如何验证 SQL 服务器(即 Windows 验证模式或混合模式)。我更喜欢混合模式。
然后在选择混合模式后,您必须配置 'SA' 密码。
在我看来,您似乎正在使用 windows 身份验证,并且只有您拥有管理员访问权限,其他所有人都配置为只读。
当您在 IIS 中部署 ASP.Net 应用程序时。默认使用AppPoolIdentity打开SQL连接,没有任何DML操作权限
上下文
我正在使用 Visual Studio 2013,我创建了一个 ADO.Net 实体数据模型,它连接到我的 SQL Server 2014 数据库。
我可以检索我的数据并使用 RESTful 服务显示它。
问题
但我无法将数据插入任何 table(也可以删除和编辑)。
我的连接是否设置为只读模式?我查看了我的数据库的属性,但没有指向该选项。
有什么帮助吗?!
已编辑:
这是我的 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模型),当点击Add User
link时从控制器调用此函数:
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;
}
}
您还需要任何详细信息吗,我还以为是数据库设置的问题?!
看起来您用于连接 SQL 数据库的用户名具有只读访问权限。您应该使用其他有权执行 DML 操作的用户名。
如果您没有其他用户名,则必须联系 SQL 服务器的 DBA
编辑
安装 SQL 服务器时,您将获得配置选项,如何验证 SQL 服务器(即 Windows 验证模式或混合模式)。我更喜欢混合模式。
然后在选择混合模式后,您必须配置 'SA' 密码。
在我看来,您似乎正在使用 windows 身份验证,并且只有您拥有管理员访问权限,其他所有人都配置为只读。
当您在 IIS 中部署 ASP.Net 应用程序时。默认使用AppPoolIdentity打开SQL连接,没有任何DML操作权限