Click here to Skip to main content
12,633,519 members (31,016 online)
Rate this:
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 21:35pm
Zoltán Zörgő 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
Please Sign up or sign in to vote.

Solution 1


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

Solution 2


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.

for parsing your string values.
for integers.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100