多个用户同时访问同一个表 [英] Multiple Users accessing same table at a same time

查看:107
本文介绍了多个用户同时访问同一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开展一个网络项目,多个用户可以保存信息。



为了保存用户信息,我写了两个用于插入用户数据的存储过程,一个用于删除先前插入的数据,具体取决于某些条件。还有另一个存储过程用于将该员工的报告绑定到网格,此过程仅包含select语句,在调用上面两个sp之后调用它。



以上存储过程使用相同的表''EmpDetails''。



我的问题是,当单个用户保存信息时,信息保存正确,但是当我同时为两个用户品尝时,我点击保存按钮就会给我带来问题,就像我的第三个sp没有为员工获得正确的报告一样。



为了解决这个问题,我使用了交易,但它对我没有用,我得到了关注错误,

 2012-12-25  12  17  14  197  [ 10 ]错误管理员无法投射 '  System.Int32'类型'  System.String'
System.InvalidCastException:无法转换类型' code-的 object string> System.Int32键入 System.String'。 System.Data.SqlClient.SqlBuffer.get_String()
在System.Data.SqlClient.SqlDataReader.GetString( Int32 i)$ b的
$ .b at System.Web.Security.SqlRoleProvider.GetRolesForUser( String username)
at System.Web.Security.RolePrincipal.GetRoles()
at System.Web.Security.Roles.GetRolesForUser( String username)
at Admin.Page_Load( Object sender,EventArgs e) in c:\Projects On IIS \SKFSheet20Dec_For_Test\Admin.master.cs:line 37





在这个位置:

 < span class =code-keyword> string  uname =会话[  UserName]的ToString(); 
string [] userroles = Roles.GetRolesForUser(uname); // 此时我收到错误。





所以请给我建议解决这个问题。

解决方案

你好,



在此行设置调试器<​​pre lang =c#> string uname = Convert.ToString(Session [ UserName]);

然后检查你会得到什么。



错误建议可能是你得到空值。






我想在你的行< br $>


 string [] userroles = Roles.GetRolesForUser(uname); 





您将错误的值传递给GetRolesForUser()函数。此函数可能需要UserId值,并且您传递的是UserName值,这是一个字符串。



使用

 Convert.ToString(); 

用于解析字符串值。

类似

 Convert.ToInt32()

表示整数。



谢谢


Hi everyone,

I am working on a web project, where multiple users can save information.

For saving information of user i have written two stored procedure one for inserting user data and one for delete previously inserted data depending upon some condition.There is another stored procedure used to bind reports of that employee to grid and this procedure contains only select statement and it is called after calling above two sp.

The above stored procedures using same table ''EmpDetails''.

My Problem is that, when single user saves the information, the information is saving correctly, but when i have tasted for two users for same time it is giving me issues when i click on save button,like my third sp didnt get correct reports for employee.

To solve this issue i have used transactions, but it didnt worked for me and i get followig error,

2012-12-25 12:17:14,197 [10] ERROR Admin Unable to cast object of type 'System.Int32' to type 'System.String'.
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.
   at System.Data.SqlClient.SqlBuffer.get_String()
   at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
   at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username)
   at System.Web.Security.RolePrincipal.GetRoles()
   at System.Web.Security.Roles.GetRolesForUser(String username)
   at Admin.Page_Load(Object sender, EventArgs e) in c:\Projects On IIS\SKFSheet20Dec_For_Test\Admin.master.cs:line 37



at this location:

string uname = Session["UserName"].ToString();
string[] userroles = Roles.GetRolesForUser(uname); // At this point i get error.



So please give me suggestion to solve this issue.

解决方案

hi,

Set debugger on this line

string uname = Convert.ToString(Session["UserName"]);

then check what you will get.

The error suggests may be you get null value.


Hi,

I think at your line

string[] userroles = Roles.GetRolesForUser(uname);



You are passing a wrong value to "GetRolesForUser()" function. This function may need the UserId value and you are passing the UserName value which is a string.

Use

Convert.ToString();

for parsing your string values.
similarly

Convert.ToInt32()

for integers.

Thanks


这篇关于多个用户同时访问同一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆