- Enjoy your brand new Visual Studio instance.
Use {version}=11.0 for Visual Studio 2012
Use {version}=12.0 for Visual Studio 2013
Software Development : A dizzy job...keeping abreast and being competitive is a 24X7 involvement
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342"/>
<bindingRedirect oldVersion="0.0.0.0-4.121.1.0" newVersion="4.112.3.0"/>
</dependentAssembly>
| Sl | Blog | Url | Description |
| 1 | Ido Flatows Blog | http://feeds.feedburner.com/IdoFlatowsBlog | Area of expertise: WCF, Azure, IIS, IIS Perf (http://feedproxy.google.com/~r/IdoFlatowsBlog/~3/qiMlWjxYP1I/fixing-iis-advanced-logging-performance-counters-errors.aspx) |
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 |
Scenario: We have a Table : TableA
Structure of TableA:
Id Name
-- ---------------------------
1 Pirate
2 Monkey
3 Ninja
4 Spaghetti
-------------------------------
Requirement: Iterate through the Names (“Name” column) of TableA
Solution:
We all know that the most convenient, easy and widely used solution is by using a Cursor.
DECLARE cursor1 CURSOR
FOR SELECT Name FROM TableA
OPEN cursor1
FETCH NEXT FROM cursor1
This works, but we should be aware of the disadvantages of using a Cursor…
Cursor implementation in application, helps data manipulation easy and even they are very effective but due to some major disadvantage of Cursor normally they are not preferred.
Disadvantages of cursors
Apart from these I would like to point out some great advantages of cursor if the entire result set must be transferred to the client for processing and display.
Some Alternatives to using a Cursor:
It has been generally observed that looping without using a cursor is faster than looping using a cursor.
Some solutions:
1. Add the recordset to a new Temp Table and also introduce a new column to the temp table.
*****************************************************
set rowcount 0
select NULL mykey, * into #mytemp from TableA
set rowcount 1
update #mytemp set mykey = 1
while @@rowcount > 0
begin
set rowcount 0
select * from #mytemp where mykey = 1
delete #mytemp where mykey = 1
set rowcount 1
update #mytemp set mykey = 1
end
set rowcount 0
*****************************************************************
2. The following solution assumes that there is a unique indexed int column named id.
declare @id char( 11 )
select @id = min( id ) from TableA
while @id is not null
begin
select * from TableA where id = @id
select @id = min( id ) from TableA where id > @id
end
****************************************************************
3. Here to the temp table we are adding a new column (RowID ) which is a identity column
DECLARE @RowsToProcess int
DECLARE @CurrentRow int
DECLARE @SelectCol1 int
DECLARE @table1 TABLE (RowID int not null primary key identity(1,1), Name varchar(50))
INSERT into @table1 (Name ) SELECT Name FROM tableA
SET @RowsToProcess=@@ROWCOUNT
SET @CurrentRow=0
WHILE @CurrentRow<@RowsToProcess
BEGIN
SET @CurrentRow=@CurrentRow+1
SELECT
@SelectCol1=Name
FROM @table1
WHERE RowID=@CurrentRow
--do your thing here--
END
******************************************************************
4.
DECLARE @table1 TABLE (
idx int identity(1,1),
col1 int )
DECLARE @counter int
SET @counter = 1
WHILE(@counter < SELECT MAX(idx) FROM @table1)
BEGIN
DECLARE @colVar INT
SELECT @colVar = col1 FROM @table1 WHERE idx = @counter
-- Do your work here
SET @counter = @counter + 1
END
Believe it or not, this is actually more efficient and performant than using a cursor.
*********************************************************************
5.
DECLARE
@LoopId int
,@MyData varchar(100)
DECLARE @CheckThese TABLE
(
LoopId int not null identity(1,1)
,MyData varchar(100) not null
)
INSERT @CheckThese (YourData)
select MyData from MyTable
order by DoesItMatter
SET @LoopId = @@rowcount
WHILE @LoopId > 0
BEGIN
SELECT @MyData = MyData
from @CheckThese
where LoopId = @LoopId
-- Do whatever
SET @LoopId = @LoopId - 1
END
*********************************************************************
6.
*********************************************************************
While fetching we should always remember that SQL Server Queries are SET Based operations and work best in circumstances dealing with SET Based operations.
You can loop through the table variable or you can cursor through it. This is what we usually call a RBAR - pronounced Reebar and means Row-By-Agonizing-Row.
So, we should always strive to find a SET-BASED answer and move away from RBARs as much as possible.
Set based queries are (usually) faster because:
Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model. Any time you have sections of UI that update dynamically (e.g., changing depending on the user’s actions or when an external data source changes), KO can help you implement it more simply and maintain-ably.
AngularJS is an open-source JavaScript framework, maintained by Google, that assists with running what are known as single-page applications. Its goal is to augment browser-based applications with model–view–controller (MVC) capability, in an effort to make both development and testing easier. The library reads in HTML that contains additional custom tag attributes; it then obeys the directives in those custom attributes, and binds input or output parts of the page to a model represented by standard JavaScript variables. The values of those JavaScript variables can be manually set, or retrieved from static or dynamic JSON resources.
http://angularjs.org/
Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
http://backbonejs.org
Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
http://nodejs.org/
Modernizr is a small JavaScript library that detects the availability of native implementations for next-generation web technologies, i.e. features that stem from the HTML5 and CSS3 specifications. Many of these features are already implemented in at least one major browser (most of them in two or more), and what Modernizr does is, very simply, tell you whether the current browser has this feature natively implemented or not.
http://modernizr.com
RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.
http://requirejs.org
LESS extends CSS with dynamic behaviour such as variables, mixins, operations and functions.LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only).
http://lesscss.org/
Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.
http://sass-lang.com
Source: http://www.codeproject.com/Articles/596800/JavaScript-Frameworks-and-Resources
var dictionary = new Dictionary { { "hello", "world!" } };
...
var something = dictionary.hello;
using System;
using System.Collections.Generic;
using System.Dynamic;
namespace AaronPowell.Dynamics.Collections
{
public class DynamicDictionary : DynamicObject
{
private IDictionary dictionary;
public DynamicDictionary(IDictionary dictionary)
{
this.dictionary = dictionary;
}
}
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
var key = binder.Name;
if (dictionary.ContainsKey(key))
{
result = dictionary[key];
return true;
}
throw new KeyNotFoundException(string.Format("Key \"{0}\" was not found in the given dictionary", key));
}
var dictionary = new Dictionary {{ "hello", "world!" }};
dynamic dynamicDictionary = new DyanmicDictionary(dictionary);
Console.WriteLine(dynamicDictionary.hello); //prints 'world'
public class DynamicDictionary : DynamicObject
{
private Dictionary _dictionary = new Dictionary();
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
return _dictionary.TryGetValue(binder.Name, out result);
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
_dictionary[binder.Name] = value;
return true;
}
public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
{
if (dictionary.ContainsKey((string)indexes[0]))
_dictionary[(string)indexes[0]] = value;
else
_dictionary.Add((string)indexes[0], value);
return true;
}
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
return _dictionary.TryGetValue((string)indexes[0], out result);
}
}
private string propertyName;
public string PropertyName
{
get { return propertyName; }
set { age= propertyName; }
}
public string PropertyName { get; set; }
public string PropertyName { get; private set; }
using System.Security;
using System.Runtime.InteropServices;
using System;
using System.Windows.Forms;
namespace SecureStringProject
{
public class SecureStringExample
{
public void ImplementSecureString()
{
SecureString secureString = new SecureString();
///Implementing AppendChar method to add
///characters to SecureString Object.
secureString.AppendChar(‘A’);
secureString.AppendChar(‘C’);
secureString.AppendChar(‘G’);
secureString.AppendChar(‘E’);
secureString.AppendChar(‘F’);
///Implementing InsertAt method to insert a character at specified index.
secureString.InsertAt(1, ‘B’);
///Implementing SetAt method to replace character
///at specified index with new character.
secureString.SetAt(3, ‘D’);
///Implementing RemoveAt method to
///remove a character at specified index.
secureString.RemoveAt(5);
///Reading SecureStrinng content.
IntPtr pointer = Marshal.SecureStringToBSTR(secureString);
MessageBox.Show(Marshal.PtrToStringUni(pointer));
///Clearing SecureString Object.
secureString.Clear();
///Disposing SecureString Object.
secureString.Dispose();
///Free BSTR pointer allocated using
///SecureStringToBSTR method.
Marshal.ZeroFreeBSTR(pointer);
}
}
}
In
the 220 milliseconds that flew by, a lot of interesting stuff happened
to make Firefox change the address bar color and put a lock in the lower
right corner. With the help of Wireshark, my favorite network tool, and a slightly modified debug build of Firefox, we can see exactly what's going on.
By agreement of RFC 2818, Firefox knew that "https" meant it should connect to port 443 at Amazon.com:
Most people associate HTTPS with SSL (Secure Sockets Layer) which was created by Netscape in the mid 90's.
This is becoming less true over time. As Netscape lost market share,
SSL's maintenance moved to the Internet Engineering Task Force (IETF). The first post-Netscape version was re-branded as Transport Layer Security (TLS) 1.0 which was released in January 1999. It's rare to see true "SSL" traffic given that TLS has been around for 10 years.
The next two bytes are 0x0301 which indicate that this is a version 3.1 record which shows that TLS 1.0 is essentially SSL 3.1.
The
handshake record is broken out into several messages. The first is our
"Client Hello" message (0x01). There are a few important things here:







Anyone
could have sent us these bytes. Why should we trust this signature? To
answer that question, need to make a speedy detour into mathemagic land:
1890572922 9464742433 9498401781 6528521078 8629616064 3051642608 4317020197 7241822595 6075980039 8371048211 4887504542 4200635317 0422636532 2091550579 0341204005 1169453804 7325464426 0479594122 4167270607 6731441028 3698615569 9947933786 3789783838 5829991518 1037601365 0218058341 7944190228 0926880299 3425241541 4300090021 1055372661 2125414429 9349272172 5333752665 6605550620 5558450610 3253786958 8361121949 2417723618 5199653627 5260212221 0847786057 9342235500 9443918198 9038906234 1550747726 8041766919 1500918876 1961879460 3091993360 6376719337 6644159792 1249204891 7079005527 7689341573 9395596650 5484628101 0469658502 1566385762 0175231997 6268718746 7514321(Good luck trying to find "p" and "q" from this "n" - if you could, you could generate real-looking VeriSign certificates.)
It's sort of a misnomer since it actually means that those are the bytes that the signer is going to sign and not the bytes that already include a signature.
The
actual signature, "S", is simply called "encrypted" in Wireshark. If we
raise "S" to VeriSign's public "e" exponent of 65537 and then take the
remainder when divided by the modulus "n", we get this "decrypted"
signature hex value:
0001FFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFF00302130 0906052B0E03021A 05000414C19F8786 871775C60EFE0542 E4C2167C830539DBPer the PKCS #1 v1.5 standard, the first byte is "00" and it "ensures that the encryption block, [when] converted to an integer, is less than the modulus." The second byte of "01" indicates that this is a private key operation (e.g. it's a signature). This is followed by a lot of "FF" bytes that are used to pad the result to make sure that it's big enough. The padding is terminated by a "00" byte. It's followed by "30 21 30 09 06 05 2B 0E 03 02 1A 05 00 04 14" which is the PKCS #1 v2.1 way of specifying the SHA-1 hash algorithm. The last 20 bytes are SHA-1 hash digest of the bytes in "signedCertificate."
The top "VeriSign Class 3 Public Primary Certification Authority" was signed by itself. This certificate has been built into Mozilla products as an implicitly trusted good certificate since version 1.4 of certdata.txt in the Network Security Services (NSS) library. It was checked-in on September 6, 2000 by Netscape's Robert Relyea with the following comment:
"Make the framework compile with the rest of NSS. Include a 'live' certdata.txt with those certs we have permission to push to open source (additional certs will be added as we get permission from the owners)."This decision has had a relatively long impact since the certificate has a validity range of January 28, 1996 - August 1, 2028.
/* cert is OK. This is the client side of an SSL connection.
* Now check the name field in the cert against the desired hostname.
* NB: This is our only defense against Man-In-The-Middle (MITM) attacks! */
This check helps prevent against a man-in-the-middle
attack because we are implicitly trusting that the people on the
certificate trust chain wouldn't do something bad, like sign a
certificate claiming to be from Amazon.com unless it actually was
Amazon.com. If an attacker is able to modify your DNS server by using a
technique like DNS cache poisoning,
you might be fooled into thinking you're at a trusted site (like
Amazon.com) because the address bar will look normal. This last check
implicitly trusts certificate authorities to stop these bad things from
happening.4456: SSL[131491792]: Pre-Master Secret [Len: 48]Note that it's not completely random. The first two bytes are, by convention, the TLS version (03 01).
03 01 bb 7b 08 98 a7 49 de e8 e9 b8 91 52 ec 81 ...{...I.....R..
4c c2 39 7b f6 ba 1c 0a b1 95 50 29 be 02 ad e6 L.9{......P)....
ad 6e 11 3f 20 c4 66 f0 64 22 57 7e e1 06 7a 3b .n.? .f.d"W~..z;
In this session, the full padded value was:wrapperHandle = fopen("plaintextpadding.txt", "a"); fprintf(wrapperHandle, "PLAINTEXT = "); for(i = 0; i < modulusLen; i++) { fprintf(wrapperHandle, "%02X ", block[i]); } fprintf(wrapperHandle, "\r\n"); fclose(wrapperHandle);
00 02 12 A3 EA B1 65 D6 81 6C 13 14 13 62 10 53 23 B3 96 85 FF 24 FA CC 46 11 21 24 A4 81 EA 30 63 95 D4 DC BF 9C CC D0 2E DD 5A A6 41 6A 4E 82 65 7D 70 7D 50 09 17 CD 10 55 97 B9 C1 A1 84 F2 A9 AB EA 7D F4 CC 54 E4 64 6E 3A E5 91 A0 06 00 03 01 BB 7B 08 98 A7 49 DE E8 E9 B8 91 52 EC 81 4C C2 39 7B F6 BA 1C 0A B1 95 50 29 BE 02 AD E6 AD 6E 11 3F 20 C4 66 F0 64 22 57 7E E1 06 7A 3BFirefox took this value and calculated "C ≡ Me (mod n)" to get the value we see in the "Client Key Exchange" record:


master_secret = PRF(pre_master_secret, "master secret", ClientHello.random + ServerHello.random)The "pre_master_secret" is the secret value we sent earlier. The "master secret" is simply a string whose ASCII bytes (e.g. "6d 61 73 74 65 72 ...") are used. We then concatenate the random values that were sent in the ClientHello and ServerHello (from Amazon) messages that we saw at the beginning.
4C AF 20 30 8F 4C AA C5 66 4A 02 90 F2 AC 10 00 39 DB 1D E0 1F CB E0 E0 9D D7 E6 BE 62 A4 6C 18 06 AD 79 21 DB 82 1D 53 84 DB 35 A7 1F C1 01 19
key_block = PRF(SecurityParameters.master_secret, "key expansion", SecurityParameters.server_random + SecurityParameters.client_random);The bytes from "key_block" are used to populate the following:
client_write_MAC_secret[SecurityParameters.hash_size]Since we're using a stream cipher instead of a block cipher like the Advanced Encryption Standard (AES), we don't need the Initialization Vectors (IVs). Therefore, we just need two Message Authentication Code (MAC) keys for each side that are 16 bytes (128 bits) each since the specified MD5 hash digest size is 16 bytes. In addition, the RC4 cipher uses a 16 byte (128 bit) key that both sides will need as well. All told, we need 2*16 + 2*16 = 64 bytes from the key block.
server_write_MAC_secret[SecurityParameters.hash_size]
client_write_key[SecurityParameters.key_material_length]
server_write_key[SecurityParameters.key_material_length]
client_write_IV[SecurityParameters.IV_size]
server_write_IV[SecurityParameters.IV_size]
client_write_MAC_secret = 80 B8 F6 09 51 74 EA DB 29 28 EF 6F 9A B8 81 B0
server_write_MAC_secret = 67 7C 96 7B 70 C5 BC 62 9D 1D 1F 4A A6 79 81 61
client_write_key = 32 13 2C DD 1B 39 36 40 84 4A DE E5 6C 52 46 72
server_write_key = 58 36 C4 0D 8C 7C 74 DA 6D B7 34 0A 91 B6 8F A7
verify_data = PRF(master_secret, "client finished", MD5(handshake_messages) + SHA-1(handshake_messages)) [12]We take the result and add a record header byte "0x14" to indicate "finished" and length bytes "00 00 0c" to indicate that we're sending 12 bytes of verify data. Then, like all future encrypted messages, we need to make sure the decrypted contents haven't been tampered with. Since our cipher suite in use is TLS_RSA_WITH_RC4_128_MD5, this means we use the MD5 hash function.
HMAC_MD5(Key, m) = MD5((Key ⊕ opad) ++ MD5((Key ⊕ ipad) ++ m)(The ⊕ means XOR, ++ means concatenate, "opad" is the bytes "5c 5c ... 5c", and "ipad" is the bytes "36 36 ... 36").
HMAC_MD5(client_write_MAC_secret, seq_num + TLSCompressed.type + TLSCompressed.version + TLSCompressed.length + TLSCompressed.fragment));As you can see, we include a sequence number ("seq_num") along with attributes of the plaintext message (here it's called "TLSCompressed"). The sequence number foils attackers who might try to take a previously encrypted message and insert it midstream. If this occurred, the sequence numbers would definitely be different than what we expected. This also protects us from an attacker dropping a message.
To encrypt a byte, we xor
this pseudo-random byte with the byte we want to encrypt. Remember that
xor'ing a bit with 1 causes it to flip. Since we're generating random
numbers, on average the xor will flip half of the bits. This random bit
flipping is effectively how we encrypt data. As you can see, it's not
very complicated and thus it runs quickly. I think that's why Amazon
chose it.
Recall that we have a "client_write_key" and a
"server_write_key." The means we need to create two RC4 instances: one
to encrypt what our browser sends and the other to decrypt what the
server sent us.
The first few random bytes out of the
"client_write" RC4 instance are "7E 20 7A 4D FE FB 78 A7 33 ..." If we
xor these bytes with the unencrypted header and verify message bytes of
"14 00 00 0C 98 F0 AE CB C4 ...", we'll get what appears in the
encrypted portion that we can see in Wireshark:
The server does almost the same thing. It sends out a "Change Cipher Spec"
and then a "Finished Message" that includes all handshake messages,
including the decrypted version of the client's "Finished
Message." Consequently, this proves to the client that the server was
able to successfully decrypt our message.
GET /gp/cart/view.html/ref=pd_luc_mri HTTP/1.1will give us the bytes we see on the wire:
Host: www.amazon.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2009060911 Minefield/3.0.10 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
...
The only other interesting fact is that the sequence number increases on
each record, it's now 1 (and the next record will be 2, etc).
The server does the same type of thing on its side using the
server_write_key. We see its response, including the tell-tale
application data header:

Decrypting this gives us:
HTTP/1.1 200 OKwhich is a normal HTTP reply that includes a non-descriptive "Server: Server" header and a misspelled "Cneonction: close" header coming from Amazon's load balancers.
Date: Wed, 10 Jun 2009 01:09:30 GMT
Server: Server
...
Cneonction: close
Transfer-Encoding: chunked
One of the cipher suites that was offered was "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" which uses the Diffie-Hellman key exchange that has a nice property of "forward secrecy."
This means that if someone cracked the mathematics of the key exchange,
they'd be no better off to decrypt another session. One downside to
this algorithm is that it requires more math with big numbers, and thus
is a little more computationally taxing on a busy server. The "Advanced
Encryption Standard" (AES)
algorithm was present in many of the suites that we offered. It's
different than RC4 in that it works on 16 byte "blocks" at a time rather
than a single byte. Since its key can be up to 256 bits, many consider
this to be more secure than RC4.
In just 220 milliseconds, two
endpoints on the Internet came together, provided enough credentials to
trust each other, set up encryption algorithms, and started to send
encrypted traffic.
And to think, all of this just so Bob can buy milk.