Tuesday, August 2, 2011

Minority Report movie in SQL

set transaction isolation level read uncommitted

select * from Crime where CommitedAt > GETDATE()

Saturday, July 30, 2011

Windows activation from cmd

little reminder.
how to activate windows via internet if it was not done after installation.

$slmgr -ato

Wednesday, July 20, 2011

And again about "Error #2006: The supplied index is out of bounds."

The error is in Network Monitor feature in Flash\Flex.
When you trying to send big amount of data from your flex application it can fail with that error.
The most interesting thing here - all your data will be successfully sent, but you will see that error.

How to solve:
..# if you are using Flash Builder Premium (Network Monitor is included) - just go to Network Monitor, disable it and rebuild your app.
..# if you are using Flash Builder Standart - follow steps below:
....#1 find .actionScriptProperties file
....#2 open it in editor
....#3 search for "includeNetmonSwc" option
....#4 set it to "false"
....#5 save file
....#6 return to Flash Builder, clean and rebuild your app.

Thursday, May 19, 2011

Compare data in List<> (Compare two Lists)

List<>.SequenceEqual() can be used to compare data in two sequences.

if you are going to store instances of your own classes, you will need to implement IEquatable and IComparable interfaces in the classes.

        class MyClass : IEquatable, IComparable
        {
            public string text { get; set; }
            public int number { get; set; }

            #region IEquatable<> methods
            public override bool Equals(object other)
            {
                return base.Equals(other as MyClass);
            }

            public bool Equals(MyClass other)
            {
                return (text == other.text) && (number == other.number);
            }

            public override int GetHashCode()
            {
                return text.GetHashCode() ^ number.GetHashCode();
            }
            #endregion

            public int CompareTo(MyClass other)
            {
                int a = this.GetHashCode();
                int b = other.GetHashCode();
                return a.CompareTo(b);
            }
        }

Now you can use SequenceEqual():

        list1.Sort();
        list2.Sort();

        list1.SequenceEqual(list2)


example:


            List list1 = new List()
                {
                    new MyClass(){ text = "text22", number = 2},
                    new MyClass(){ text = "text11", number = 1}
                };

            List list2 = new List()
                {
                    new MyClass(){ text = "text11", number = 1},
                    new MyClass(){ text = "text22", number = 2}
                };

            list1.Sort();
            list2.Sort();

            if (list1.SequenceEqual(list2))
            {
                Console.WriteLine("equal");
            }

Wednesday, May 4, 2011

Read-only tables in MS SQL

here is description how to make readonly table[s] in MS SQL using filegroups:
#1 Create new filegroup;
#2 Add file into the filegroup;
#3 Create new of move existing table[s] into the filegroup;
#4 Change DB mode to SINGLE_USER;
#5 Modify filegroup to be readonly;
#6 Change DB mode to MULTI_USER.

notes:
Table can't be moved into other filegroup using "Alter table".
but you can use "CREATE CLUSTERED INDEX" instead, table will be automatically moved into the new filegroup.

examples:
ALTER DATABASE db_name ADD FILEGROUP FG_READONLY;

    ALTER DATABASE db_name ADD FILE( 
        NAME = 'logic_name_here', 
        FILENAME = 'os_file_name_here', 
        SIZE = 10, 
        FILEGROWTH = 10%,
        MAXSIZE = UNLIMITED ) TO FILEGROUP FG_READONLY;
    GO

    CREATE CLUSTERED INDEX IX_Table_Temp ON dbo.Table(ID) ON FG_READONLY
    GO 

    DROP INDEX IX_Table_Temp ON dbo.Table
    GO

    ALTER DATABASE db_name SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    GO
    
    ALTER DATABASE db_name MODIFY FILEGROUP FG_READONLY READONLY;
    GO
    
    ALTER DATABASE db_name SET MULTI_USER;
    GO

links:
Filegroups in SQL Server 2005
How to make a table Read Only in SQL Server

Thursday, February 17, 2011

HD Tune. ST32000542AS and WD1002FAEX-00Z3A0

Here is HD Tune tests for:
#1 WD WD1002FAEX-00Z3A0 (1000 GB)
#2 Seagate ST32000542AS (2000 GB)

Альбом: Изображения Blogger

Альбом: Изображения Blogger

Friday, January 7, 2011

Add record to a history table in case when data was changed

insert into History
values (F1, F2, F3)
select
   @New_F1_Val as F1,
   @New_F2_Val as F2,
   @New_F3_Val as F3
except
select * from
  (
    select top 1 F1, F2, F3
    from History
    order by At desc
  ) x

this code will add nothing to the History table in case when most recent record equals to the new values