Wednesday, September 24, 2014

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

<configuration>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
</configuration>

Friday, September 19, 2014

Wednesday, September 17, 2014

Delete all data in SQL Server database

-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' 
GO 
 
EXEC sp_MSForEachTable 'SET QUOTED_IDENTIFIER ON; DELETE FROM ?' 
GO 
 
-- enable referential integrity again 
EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL' 
GO
 
-- Reseed identity columns
EXEC sp_MSForEachTable 'DBCC CHECKIDENT (''?'', RESEED, 0)'

DELETE failed because the following SET options have incorrect settings: QUOTED_IDENTIFIER

-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' 
GO 
 
EXEC sp_MSForEachTable 'SET QUOTED_IDENTIFIER ON; DELETE FROM ?' 
GO 
 
-- enable referential integrity again 
EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL' 
GO
 
-- Reseed identity columns
EXEC sp_MSForEachTable 'DBCC CHECKIDENT (''?'', RESEED, 0)'

Tuesday, September 16, 2014

Console.WriteLine equivalent in ASP.Net

System.Diagnostics.Debug.WriteLine("Message");

Messages are displayed in output window

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details

try
{
    //...........
    dc.SaveChanges();
}
catch (DbEntityValidationException ex)
{
    foreach (var eve in ex.EntityValidationErrors)
    {
        System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
            eve.Entry.Entity.GetType().Name, eve.Entry.State);
        foreach (var ve in eve.ValidationErrors)
        {
            System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                ve.PropertyName, ve.ErrorMessage);
        }
    }
}
Look for errors in the output window during debugging

LINQ Lamda Syntax - Selecting multiple columns

use the new keyword
var parent = dc.Forms.Select(f => new { f.FormID, f.ModuleId })

How to check if string contains a string from a string array

Using LINQ Any
string[] rpts = { "rpt""rtp""Rpt""Report" };
using if and any to check whether string contains any item from array
if (rpts.Any(url.Contains))
{
    ........
}

Monday, September 8, 2014

Bind a Dictionary to a DropDownList

Dictionary<stringstring> openWith = new Dictionary<stringstring>();
 
// Add some elements to the dictionary. There are no  
// duplicate keys, but some of the values are duplicates.
openWith.Add("txt""notepad.exe");
openWith.Add("bmp""paint.exe");
openWith.Add("dib""paint.exe");
openWith.Add("rtf""wordpad.exe");
 
DDL.DataSource = openWith
    .Select(r => new KeyValuePair<stringstring>(r.Key, r.Value))
    .ToList();
DDL.DataTextField = "Key";
DDL.DataValueField = "Value";
DDL.DataBind();

call change() event handler if I select radio button programatically

$(function () {
    $('input[name=type]').change(function () {
        alert($(this).val());
    });
    $('input[value=SV]').attr('checked''checked').trigger('change');
});

Saturday, September 6, 2014

EF5: Cannot attach the file ‘{0}' as database '{1}'

Go to View -> SQL Server Object Explorer and delete the database from the (localdb)\v11.0 subnode!

Delete the database

The model backing the context has changed since the database was created

Database.SetInitializer<YourDbContext>(null);
or


Database.SetInitializer(new DropCreateDatabaseIfModelChanges<YourDbContext>());
for later versions