Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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.
Posted 24-Dec-12 20:35pm
Comments
Zoltán Zörgő at 25-Dec-12 3:36am
   
Most likely you get a NULL back. Are you sure you are not deleting something that should not be deleted at that point? You wrote: "one for delete previously inserted data depending upon some condition". Be careful why you are doing there!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 25 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid