Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Monday, January 27, 2014

How to loop through a collection that supports IEnumerable?

Whenever you get to this issue, though it seems a really easy job to do here 2 ways how you can iterate on a collection that supports IEnumerable:

First one using a foreach statement:

foreach (var item in collection)
{
    // play with your item
}

I suggest that always when you know your object types of collection to use that type instead of var. I always try to avoid var type. It is something that my team lead advised me and I came to realize it is a good practice.

Then second way to do it is using for statement. Whenever you have a collection and you need to iterate it and according to some conditions some elements might have to be removed you cannot use foreach because you will have a nice error saying: "Collection was modified; enumeration operation may not execute" :) So that is why you need to use for statement.

for(int i = 0; i < collection.Count(); i++) 
{
    string str1 = collection.ElementAt(i);
    // play with your item
}

There might be other ways to iterate, like using GetEnumerator but is enough, for the moment :)
Have a nice day.

Monday, November 26, 2012

How to solve error 15128 in Microsoft Sql Server ?

If you ever meet this nice Sql Error, 15128 in Microsoft Sql Error you must do these next steps. At least they worked for me :)
First I want to explain which is the scenario. You are logged with Windows Authentication and you created a new sql login. Now you want to disable Enforce Password Policy. When you want to do that Sql tells you that you can not save the user, a new password must be set. Strange...so:

  • double click on new login created, leave the check boxes checked(enforce password policy and enforce password expiration) and change user's password temporally to what ever you want, click OK
  • then reopen and uncheck enforce password policy, enforce password expiration; Press OK
  • finally you reopen the user and specify the password you want
  • Test it ;)
Hope this will help you.