How to Hide HTML Elements and How to Find Named SQL Server Instances With the SQL Server Browser Service

I learned some stuff the other day at work that maybe should be obvious, but it wasn’t obvious to me and so what I’m going to do is start a new blog category named “Stuff I’ve Learned”. The two things in this post could probably also be filed in another category called “Duh” but I haven’t decided yet if that is a good idea — maybe after writing this I will decide.

database administrator

Well, what have I learned? The first item was about HTML and CSS and really Javascript as well — you might call this “DHTML” but who am I to judge? The second was about SQL Server and how a client (e.g. Query Analyzer or a website) resolves a named instance of a SQL Server.

  1. You can hide a DIV element using visibility:hidden; in CSS, and then show one of the child elements of the DIV using Javascript, without modifying the visibility of the DIV. How about that!
    I have a demo HTML page that is similar to our real scenario, having two radio buttons and an image in an invisible DIV. The first radio button makes the DIV visible, which, as you would expect, shows the image that is a child element of the DIV. This is how I thought you would need to do things. The second radio button in the example page shows only the image, without showing the parent DIV element — and it still works! This was unexpected for me because surely an element shouldn’t be shown if it is inside another, invisible element? This works in Internet Explorer 6 and Firefox 2 but I haven’t tried any other browsers.
  2. We’ve been setup new SQL Servers at work and maybe to save IP addresses, or maybe to ease administration (DNS entries? Server administration overhead?) load, we are using named SQL Server instances on a single hostname (e.g. BNESQL5000\SQL5000) where BNESQL5000 is the hostname and SQL5000 is the name of the SQL Server instance on the server.

    Now the other afternoon, I could connect fine to the named instance using Query Analyzer, which I had running since that morning. Another dude at work couldn’t connect using Enterprise Manager (ergh, clicking — I’ll do it with SQL cause I’m a Real Programmer). Obviously I was connected and using the server, so it wasn’t a problem with the SQL Server instance itself — it was running fine. So I ran netstat on my PC to see which TCP port I was connected to the SQL Server on. It was port 50433 incidentally, so I said to my Enterprise Manager-using friend, “Try BNESQL5000,50433″ as your SQL hostname, which sneakily connects directly to the named instance without using its name. Well voila, my Enterprise Manager-using friend connected straight up and started hammering out database changes with his clicky mouse like a demon.

    You’re probably wondering, “Omg Glenn, tell me how this named instance and TCP port magic happens!” and that’s great because I am going to tell you. The way it happens is that when you try to connect to a named SQL Server instance your client goes “uhh, the bit before the backslash is a hostname, duhhh, but there’s a backslash so, um, that’s the name of an instance innit?” and so it connects to port 1434 (standard SQL Server port of 1433, plus one) which is where the SQL Server Browser service is listening. There, the client asks the question of “which port is named instance ‘SQL5000′ listening on?” and the SQL Browser replies with port 50433. So then the client goes “BOOYA!” and connects to port 50433 without any complaints or further ado.

    So obviously, the problem was that the SQL Browser service wasn’t running on our server, after it was rebooting or something silly. I smugly informed the DBAs what was going on and they fixed the problem in no time. All was well.

So here ends Lesson One of “Stuff I’ve Learned”, I hope it was informative and sufficiently brief! :D

Comment (1)

  1. iian wrote::

    Heh, anything that takes some of the starch out of Nithy’s shirt can’t be bad.

    Tuesday, June 10, 2008 at 10:35 am #