QText 3.30

QText screen

One feature that was survived unchanged through versions and versions of QText was search. You could search only within current tab and that’s all you could do. Even when folders got added search was still limited to single file.

Well, not anymore. Finally you can search across all folders and files. Or you can limit search to current folder only. Choice is yours. Only real limit is searching through encrypted files which is not supported for security reasons. For them search will work only when you have them currently open (and thus decrypted).

Happy searching.

ListView Iterations

If there is need to iterate through ListView items, I often see following code:

foreach (var item in listView1.Items) {
    var itemX = (ListViewItem)item;
    //do something with itemX
}

Unfortunately C# compiler is not smart enough to notice that item is actually ListViewItem so it keeps it as Object. And thus we need to cast it to our desired type.

Well, actually there is no need to do this. One just needs to remember live before implicit typing with var came:

foreach (ListViewItem item in listView1.Items) {
    //do something with item
}

This still works and it definitely looks nicer.

SQL Access Denied

Illustration

As I did forced reinstall of my development environment I decided to move all my SQL Server databases to virtual disk. It seemed like a good choice, especially since I formatted virtual disk as exFAT. Since I have dual boot that means that I can use same database from both machines without dealing with all that pesky security.

Well, I was wrong. First message that greeted me was dreadful Access Denied. SQL Server would not attach, create or otherwise do anything with anything on that drive.

I’ll skip some debugging and head smacking and present you only with result: In services find SQL Server instance and change Log on as property to Local System account instead default of Network Service. That will allow it access your attached virtual disk.

Security-wise Network Service is much better account for hosting SQL Server. And in production I would definitely go with either it or separate account only for SQL Server. However, having SQL Server running as Local Service is convenient and good enough for development environment.

P.S. Once you attach database, you can switch back to Network Service account. It seems that error appears only on initial attach.

SQL Server 2012 Fun

Illustration

On clean installation of Windows 8 I had issues with Visual Studio 2012 being completely broken. Almost every day I had to deal with following messages (just an excerpt):

  • The 'Microsoft.VisualStudio.Editor.Implementation.EditorPackage' package did not load correctly.
  • The 'Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage, Microsoft.VisualStudio.QualityTools.TestCaseManagement, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' package did not load correctly.
  • The 'Windows Forms Designer Package' package did not load correctly.
  • The 'Code Analysis Package' package did not load correctly.
  • Internal error occurred. Additional information: ''.
  • NoWarn: Configuration system failed to initialize

I blamed Windows 8 and it is probably best for all that I never killed anybody given how close I live to Microsoft headquarters.

I was wrong.

I installed clean Windows 7 and same problems started again. Visual Studio would work for a while and then it would stop. Repair would fix everything but things would break soon enough. To make things more confusing, another (virtual boot) Windows 7 installation on same machine had Visual Studio 2012 that had no issues at all. So I went into task of comparing everything.

To keep long story short, I found one major difference. I had Visual Studio 2010 installed there. And, by magic, it prevented errors in Visual Studio 2012. And then I remembered that every time something went wrong SQL Server 2012 was just around corner smiling from within its Visual Studio 2010 shell.

For some reason SQL Server 2012 kept destroying Visual Studio 2012 environment. I saw simple solution - just install Visual Studio 2010 side-by-side and problems will go away. Or even simpler one - just remove SQL Server 2012 altogether and go back to SQL Server 2008 R2.

SQL Server team is my newest hate target these days. Not because of this VS 2010 shell issue but because they make uninstall extremely annoying. It consists of at least 15 different components (approximate figure, I was to annoyed to count) and I can only compare procedure to removing malware. And that is broken for quite a few versions now. If they can make single installer, why is single uninstaller impossible task?

LDAP Authentication From C#

using (var ldap = new LdapConnection(new LdapDirectoryIdentifier(this.HostName))) {
    ldap.SessionOptions.ProtocolVersion = 3;

    ldap.AuthType = AuthType.Anonymous;
    ldap.Bind();
    var dn = GetDn(ldap, userName);

    ldap.AuthType = AuthType.Basic;
    try {
        ldap.Bind(new NetworkCredential(dn, password));
        return GetUser(ldap, dn);
    } catch (LdapException) {
        return null;
    }
}

First step is just simple anonymous bind to retrieve distinguished name based on user name. If our UID is jdoe, we simply search for uid=jdoe in dc=localdomain (base DN) using sub-tree search. That should give us location of our user wherever he is. Let’s assume that user is now found at uid=jdoe,ou=People,dc=localdomain.

Full DN of user is then used together with password to authenticate ldap connection. If authentication fails our user cannot logon. If it works than another ldap search (uid=jdoe,ou=People,dc=localdomain) retrieves attributes, packs them into class and returns it back.

Sweet and simple.

P.S. Code in this post is just an excerpt. You can download full code here.