Best way to remove duplicate entries from a data table

DataTable dtIds = GetReservationIds(dtAllReservations);

var duplicates = dtIds.AsEnumerable().GroupBy(r => r[0]).Where(gr => gr.Count() > 1).ToList();

if(duplicates.Any())Console.WriteLine("Duplicate found for Classes: {0}",String.Join(", ", duplicates.Select(dupl => dupl.Key)));
string ceva = String.Join(", ", uniqueIds.AsEnumerable().Select(x => x[0].ToString()));

var UniqueRows = dtIds.AsEnumerable().Distinct(DataRowComparer.Default);
DataTable dt2 = UniqueRows.CopyToDataTable();

How to fix ERR_UNSAFE_PORT error on Chrome when browsing to unsafe ports

Error 312 (net::ERR_UNSAFE_PORT): Unknown error.

Right Click on Chrome shortcut >> Properties >>Then Append --explicitly-allowed-ports=xxx to shortcut target

Example:

C:\Documents and Settings\User\Local Settings\Application Data\Google\Chrome\Application\chrome.exe –explicitly-allowed-ports=6666

 

Not all ports are supported by the web security service. The following is a list of all supported ports:

  • HTTP: 80, 81, 1025-65535
  • HTTPS: 443, 563, 8443
  • FTP: 21

 

source:

http://superuser.com/questions/188006/how-to-fix-err-unsafe-port-error-on-chrome-when-browsing-to-unsafe-ports

http://jazzy.id.au/default/2012/08/23/why_does_chrome_consider_some_ports_unsafe.html

Show database procceses

SET NOCOUNT ON
DECLARE @DBName VARCHAR(50)
SELECT @DBName = ‘TransferInventory’
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID(‘tempdb..#tmpSpwho2’))
DROP TABLE #tmpSpwho2

CREATE TABLE #tmpSpwho2 (SPID INT, Status VARCHAR(100), Login VARCHAR(100), HostName VARCHAR(100), Blkby VARCHAR(100), DBName VARCHAR(100), Command VARCHAR(50), CPUTime INT,
DiskIO INT, LastBatch VARCHAR(100), ProgramName VARCHAR(100), SPID2 INT, REQUESTID INT)

INSERT INTO #tmpSpwho2 EXEC sp_who2
SELECT ‘kill ‘ + CAST(SPID AS VARCHAR(5)) FROM #tmpSpwho2 WHERE DBName = @DBName

Stocate modificate in utlima vreme

alternativa la view dependencies

select * from sys.objects so JOIN sys.syscomments sc ON so.object_id=sc.id WHERE type=’P’ and text like ‘%ReservationCityFees%’
====================================================

ce stocate au fost modificate in utlimele 7 zile

SELECT name
FROM sys.objects
WHERE type = ‘P’
AND DATEDIFF(D,modify_date, GETDATE()) < 7

‘Operation is not valid due to the current state of the object’ error during postback

Error:

System.InvalidOperationException: Operation is not valid due to the current state of the object.

[InvalidOperationException: Operation is not valid due to the current state of the object.]    System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +11372207    System.Web.HttpRequest.FillInFormCollection() +329

[HttpException (0x80004005): The URL-encoded form data is not valid.]    System.Web.HttpRequest.FillInFormCollection() +11486290    System.Web.HttpRequest.get_Form() +157    System.Web.HttpRequest.get_HasForm() +11487092    System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +141    System.Web.UI.Page.DeterminePostBackMode() +100    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

Solution:

<appSettings>
  <add key="aspnet:MaxHttpCollectionKeys" value="1001" />
</appSettings>

Microsoft recently (12-29-2011) released an update to address several serious security vulnerabilities in the .NET Framework. One of the fixes introduced by MS11-100 temporarily mitigates a potential DoS attack involving hash table collisions. It appears this fix breaks pages that contain a lot of POST data. In our case, on pages that have very large checkbox lists. Why would this be the case?

Some non-official sources seem to indicate that MS11-100 places a limit of 500 on postback items. I can’t find a Microsoft source that confirms this. I know that View State and other framework features eat up some of this limit.

source: http://stackoverflow.com/questions/8684049/asp-net-ms11-100-how-can-i-change-the-limit-on-the-maximum-number-of-posted-for

Alternative reading: http://www.webreference.com/programming/asp/ASPNet-Exception-Handling/index.html

Add Item to Array

There is no Add method for basic arrays.
//Add an item to the end of an existing array
string[] ar1 = new string[] {“I“, “Like“, “To“}

// create a temporary array with an extra slot
// at the end

string[] ar2 = new string[ar1.Length + 1];

// add the contents of the ar1 to ar2 at position 0
ar1.CopyTo(ar2, 0);

// add the desired value
ar2.SetValue(“Code.”, ar1.Length);

// overwrite ar1 with ar2 the contents of ar1 should now be {“I”, “Like”, “To”, “Code.”}
ar1 = ar2;

Or:
Array.Resize(ref ar1, ar1.Length + 1);
Array.Copy(new object[] { “Code.” }, 0, ar1, ar1.Length – 1, 1);

Slow SQL Server Delete

If you have referential integrity set up between your tables, you need to ensure that all foreign key columns are indexed – otherwise when you delete a record from a primary key table, referential integrity checks will cause table scans on the referring foreign key tables, and scans are terribly slow compared to index lookups.