[Exception] Collection was modified; enumeration operation may not execute

Solution : replace for each loop to standard loop

 


ArrayList items = new ArrayList();

//foreach (var item in items)
//{
// //do something
//}

for (int i = 0; i < items.Count; i++)
{
//do something
}


Referece: http://alitarhini.wordpress.com/2011/04/06/collection-was-modified-enumeration-operation-may-not-execute/

SQL scripts - Delete all Tables, Procedures, Views and Functions

Delete All Tables


DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
WHILE (@@FETCH_STATUS = 0)
BEGIN
Exec SP_EXECUTESQL @Sql
FETCH NEXT FROM @Cursor INTO @Sql
END
CLOSE @Cursor DEALLOCATE @Cursor
GO
EXEC sp_MSForEachTable 'DROP TABLE ?'
GO



Delete All Stored Procedures



declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'p'
open cur

fetch next from cur into @procName
while @@fetch_status = 0
begin
if @procName <> 'DeleteAllProcedures'
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end

close cur
deallocate cur

Delete All Views



declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'v'
open cur

fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop view ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur


Delete All Functions



declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'fn'
open cur

fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop function ' + @procName)
fetch next from cur into @procName
end

close cur
deallocate cur

Umbraco v4 - delete Recycle Bin by T-SQL


--Verify the number of nodes returned is the save as the number of nodes that is in the Recycle Bun
--select count(*) from umbracoNode where path like '%-20%' and id!=-20

begin transaction
DELETE FROM umbracoRelation WHERE parentId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
DELETE FROM umbracoRelation WHERE childId IN (SELECT id FROM umbracoNode WHERE path LIKE '%-20%' AND id != -20)
delete from cmsPreviewXml where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from cmsContentVersion where contentId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from cmsDocument where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from cmsContentXML where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from cmsContent where nodeId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from cmsPropertyData where contentNodeId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from umbracoRelation where parentId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from umbracoRelation where childId in (select id from umbracoNode where path like '%-20%' and id!=-20)
delete from umbracoDomains WHERE domainRootStructureID in (SELECT id FROM umbracoNode WHERE path like '%-20%' and id != -20)
delete from cmsTask where nodeid in (SELECT id FROM umbracoNode WHERE path like '%-20%' and id != -20)
delete from umbracoUser2NodePermission where nodeId in (SELECT id FROM umbracoNode WHERE path like '%-20%' and id != -20)
-- delete the XML nodes....
delete from umbracoNode where path like '%-20%' and id!=-20
commit transaction
--Verify is done , replace rollback to commit

--Reference : http://our.umbraco.org/forum/using/ui-questions/26114-Delete-recycle-bin-problem?p=1

Entity Framework - not have a primary key defined

Condition :
Add ADO.NET Entity Data Model > Right click >  update Model from database > pick table/view

VS Output:
The model was generated with warnings or errors.
Please see the Error List for more details. These issues must be fixed before running your application.

Open edmx file with XML editor have error :








Solution:


SELECT ISNULL((ROW_NUMBER() OVER (ORDER BY column1 DESC)), 0) AS ‘ID’, column1, column2
FROM  dbo.sample


 


Reference link :
http://www.hilmiaric.com/?p=95
http://www.ericsdavis.net/index.php/2009/03/14/entity-framework-and-primary-key-inference/
http://stackoverflow.com/questions/745341/can-sql-server-views-have-primary-and-foreign-keys