Developing for SQL Server merge replication

Lately, we’ve been pushing our application from single server environment into an environment with merge replication. Not only that, but we also migrated from another RDBMS to Microsoft SQL server. While application had no issues working in replication environment, I learned the hard way there are some things that I could and should have done better. This are my findings.

[Read the rest of this entry…]

Quick tip: Creating multiple user controls with simillar properties

Imagine you just created 4 or 5 or n different Web user controls in your ASP.NET WebForms application. Now you realized that they all share some properties. This is a problem, because it means you are having nearly identical code in multiple spots. What you can do is create a partial public class that inherits from System.Web.UI.UserControl class and put in all properties that your controls share. Then go to each and every of your user controls and change inheritance to your own class instead of System.Web.UI.UserControl.

Class from which your controls inherit:

public partial class MyControl : System.Web.UI.UserControl
{
	#region Properties

	public string Title { get; set; }
	public string Singature { get; set; }

	#endregion
}

This is how you use it in your controls (red represents original line):

public partial class MyControl1 : MyControl
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
	...
}

public partial class MyControl2 : MyControl
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
	...
}

And now, you can do something like:

<mytag:mycontrol ID="mc1" runat="server" Title="My title" Signature="Lotushints" />

for every control that inherits MyControl class

Microsoft cuts passwords to 16 chars

This week a big news broke out. Web mail service Hotmail apparently cut passwords to 16 character of length for years, despite allowing users to enter unlimited number of characters. According to arstechnica.com this applies to all Microsoft online services, i.e. Passport authentication.

Now, this in itself is not a worry. Allowing 16 characters is plenty and secure enough to not allow a brute force attack. Even by using rainbow tables an attacker would be helpless. However, to implement a maximum 16 character password one would either have to implement this password policy from start up or one would have to store passwords in plain text. The first one is not a worry, however, the second one suggest plain text passwords, which are a no-no and something that even a HelloWorld programmer should never do. Ever!

Personally I use Hotmail services since 1998 and, to be honest, I never had any problems using it. So, I can make an assumption, that passwords were trimmed to 16 character length and then protected by whatever protection is used by Microsoft. Hence, the news is only of sensational value.

Version 2.0

When I started this blog, a page theme was the last thing on my mind and to be honest, I thought a generic one would do. As more time passed, I started noticing things that I really didn’t like. For instance, a search window was a background image and cursor was not centered. Or the fact that the site corrupted in an instant someone had different font size. Thus, as you might have noticed in recent days, the site got a long needing and deserving design and content overhaul. Lord and behold, what you are seeing now is my first ever custom WordPress theme named Lotushints (how original).

Idea was to get rid of that early 2000s rich web site outlook and go for pure simplicity. Also, I wanted to organize articles a bit. Thus, categories were reduced from 20 (!) down to 3:

  • Tech stuff – where all technical and development articles are located;
  • Geekland – where you can find my rants, observations and interesting things from tech world outside software development;
  • Book reviews – for occasional rant or recommendation about books I read and found worthy writing about.

All three categories found place in main navigation as well, which meant I could scratch Categories section from right sidebar. I also decided to put entire blog archive in the main navigation as it is way too long to act as a normal sidebar item. All that sidebar item scrapping meant that I could easily move from two sidebar layout to only one, which leaves more space for articles.

That’s it really. I would really like to hear your opinions though.

Quick tip: Templated controls

If you create a templated server control, import it into your web-site or web application and you want to do:

<my:Control ID="myControl" runat="server">
   <ItemTemplate>
      Some text, html or whatever.
   </ItemTemplate>
</myControl>

and you are allowed to do only:

<my:Control ID="myControl" runat="server" />

you need to modify your ItemTemplate property to look like this:

[TemplateContainer(typeof(MyTemplateControl))]
[Browsable(false)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate ItemTemplate {
   get { ... }
   set { ... }
}

Generics

For years, I have tried to learn more about generics, but since my work was never in need for such implementation, I never bothered. Finally, an opportunity arose. I cannot go in specific details, but I had to write a Windows service (in C#) that daily obtains vast amount of similar data which must then be written to half a dozen tables of exactly the same structure. At this point, I would like to add, that amount of data obtained and amount of destination database tables are due to change at any point in future.

 

What are Generics?

According to Microsoft MSDN site “Generics allow you to define type-safe classes without compromising type safety, performance, or productivity. You implement the server only once as a generic server, while at the same time you can declare and use it with any type”. In reality this translates to the fact that if you must implement a class or function that needs to do same thing for different types, you can only write it once.

In .NET world, most of us use Generics daily, without knowing it. They are disguised as lists, collections and dictionaries.

[Read the rest of this entry…]

Clean code by Robert C. Martin

There are authors that suit you and there are authors that don’t. Having spent a decent amount of time to get through Clean Code: A Handbook of Agile Software Craftsmanship, I have found out, that Mr. Martin fails to suit me. His self admiration and belief that he is new software messiah (and as such, cannot be mistaken) is intolerable to the extent, when I literally had to convince myself from chapter to chapter to read the book until bitter and inconclusive end.

[Read the rest of this entry…]

.NET Custom validators – perfect tool (almost)

I don’t know about you, but working with .NET validators is always a fiddly job. Sure, they enable you to do quick validations, but I am yet to find an app where each field only needs one validator. And this is where things usually get interesting.

[Read the rest of this entry…]

Happy New Year

This year’s post count is getting a +1.

I wish you all a belated merry Christmas and a really happy, healthy and successful new year 2012.

DB2 Data Provider for .NET – followup

A few months back I wrote this article on DB2 Data Provider for .NET, describing issues with .NET provider and certain DB2 SQL commands e.g. CURRENT DATE function or CASE statement. As this things go, it took several months to communicate things with IBM tech support and I have to say they were very responsive and managed to tilt me only once. So kudos to them.

Good news is that IBM Tech support did acknowledge this issue. Unfortunately, the bad news is, they cannot do nothing about it, as the problem is in SQL parser in Visual Studio, which uses Other parser for DB2 queries and hence finds a problem with non-standard functions.  I was a tad startled by their solution that I should contact Microsoft on this issue. Now, I don’t want to claim that Microsoft doesn’t care about their customer satisfaction, as that would be a lie. However, I sincerely doubt that they care that DB2 Data Provider for .NET, which is IBM’s plug-in for a product that is supposed to be a competition to their MSSQL. works at all.

So, as IBM is not going to talk with Microsoft about this issue, and I am certainly not, it appears that all we can do is wait that one of the big guys comes to their senses and does something about it. Until then, you can use a workaround, which will require you to remove all case statements and CURRENT DATE calls from your typed data-sets at point of creation. You can add them on later and despite reported error, it will work. But beware that data-set will not get generated, if you keep case statements and CURRENT DATE calls.