Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

datareader threw an exception of type 'system.indexoutofrangeexception'

$
0
0

Hi,

I have a ado.net code which was fetching user details from the db and displaying. It was working fine. Now its decided to enrypt them. Once the encryption is done, I get an error 

datareader threw an exception of type 'system.indexoutofrangeexception

at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)

at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)

at System.Data.SqlClient.SqlDataReader.get_Item(String name)

Note: No sp change, No datatype changes, just that we are getting the encrypted values, decrypting it and sending to the ui. 

Initiall trouble shooting says that the colum dosent exists, however, there is no difference in column names.  FirstName, LastName ,Email ,etc are the column names. 

user = new User();
user.FirstName = Decrypt(dr["FirstName"].ToString()); user.LastName = Decrypt(dr["LastName"].ToString()); user.Email = Decrypt(dr["Email"].ToString());

Further searches suggest that number of columns returned by sp should be equal to properties in model. Infac, the columns returned are less than that in the model. Inspite of all that, I could not resolve the issue. Any suggestions? 


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>