The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,927 other followers

Archive for November 7th, 2012

Wally and testing the new 3-D printer – via: Dilbert comic strip for 11/05/2012

Posted by jpluimers on 2012/11/07

Once every while a Dilbert strip is so great, you *have* to re-publish it.

So here it goes: Wally and testing the new 3-DD printer.

Wally and testing the new 3-D printer (Dilbert comic strip for 11/05/2012 from the official Dilbert comic strips archive.)

–jeroen

via: Dilbert comic strip for 11/05/2012 from the official Dilbert comic strips archive..

Posted in Comics | Leave a Comment »

.NET/C#: SqlClient ConnectionString keys and their equivalences

Posted by jpluimers on 2012/11/07

A while ago I needed to shorten SqlClient ConnectionStrings. One way to do that is to use the shortest Key for each property (and not use the default key names that are much longer).

I beefed up the code to show you both the shortest and all equivalent keys (a few of the Microsoft exams want you to memorize most of these).

The HTML table below (similar to the huge and therefore hard to read table on MSDN) comes directly from the C# code at the bottom of the post. The only post-editing I did was making the header row bold.

Key ShortesEquivalentKey EquivalentKeys
Application Name app Application Name,app
ApplicationIntent ApplicationIntent ApplicationIntent
Asynchronous Processing async Asynchronous Processing,async
AttachDbFilename AttachDbFilename AttachDbFilename,extended properties,initial file name
Connect Timeout timeout Connect Timeout,connection timeout,timeout
Connection Reset Connection Reset Connection Reset
Context Connection Context Connection Context Connection
Current Language language Current Language,language
Data Source addr Data Source,addr,address,network address,server
Encrypt Encrypt Encrypt
Enlist Enlist Enlist
Failover Partner Failover Partner Failover Partner
Initial Catalog database Initial Catalog,database
Integrated Security trusted_connection Integrated Security,trusted_connection
Load Balance Timeout connection lifetime Load Balance Timeout,connection lifetime
Max Pool Size Max Pool Size Max Pool Size
Min Pool Size Min Pool Size Min Pool Size
MultipleActiveResultSets MultipleActiveResultSets MultipleActiveResultSets
MultiSubnetFailover MultiSubnetFailover MultiSubnetFailover
Network Library net Network Library,net,network
Packet Size Packet Size Packet Size
Password pwd Password,pwd
Persist Security Info persistsecurityinfo Persist Security Info,persistsecurityinfo
Pooling Pooling Pooling
Replication Replication Replication
Transaction Binding Transaction Binding Transaction Binding
TrustServerCertificate TrustServerCertificate TrustServerCertificate
Type System Version Type System Version Type System Version
User ID uid User ID,uid,user
User Instance User Instance User Instance
Workstation ID wsid Workstation ID,wsid

The code below uses a few techniques referenced as StackOverflow links:

  1. Sorting enumerable strings using LINQ.
  2. Generating CSV from an enumerable strings using LINQ and string.Join.
  3. Converting a DataTable to an HTML Table using an ASP.NET DataGrid and HtmlTextWriter to do the rendering.
  4. Getting a private static field by name using reflection.

Both the main program and the SqlConnectionStringBuilderHelper class are less than 70 lines of code (each about 50 when excluding comments and empty lines).

The SqlConnectionStringBuilderHelper uses the internals of the SqlConnectionStringBuilder class (all DbConnectionStringBuilder descendants I have seen work in a similar way):

  • each DbConnectionStringBuilder instance has a public Keys property that exposes the static _validKeywords field of the descendant. It contains all possible keys that can appear in a generated ConnectionString.
  • the SqlConnectionStringBuilder class (and other DbConnectionStringBuilder descendants) has a static private property _keywords that maps all possible keyword strings (including equivalents) to an enumerator (which indexes into the Keys property).
    Mono uses the same mechanism.
  • The trick is to walk the _keywords property and search for equivalent keywords.
  • For a list of equivalent keywords, you find the shortest one.

Related:

Enjoy the code: Read the rest of this entry »

Posted in .NET, ASP.NET, C#, C# 3.0, C# 4.0, C# 5.0, CSV, Development, LINQ, Software Development | Leave a Comment »

 
%d bloggers like this: