Problems????

Image by essecento via Flickr

You might be familiar with the following scenario:

You have a SQL Server database server hosting more than one database, but you just so happen to be accessing one in particular from your development environment (Query Analyser, Management Studio, etc).

So, you run a little query to automatically connect you to this database when you connect to the server. You might try something like:

Exec sp_defaultdb @loginame='DOMAIN\UsrNam', @defdb='SomeDatabase';

So, now when you log on, your database is ready and waiting to be used without having to manually select it. I have found this scenario common in development environments, when you are typically running lots of ad-hoc SQL queries, or running in code (stored procedures, views, triggers, etc) against the database.

However if you are working on different databases on the same server, defaulting to a particular one can cause you problems if you need to run in code against a different database. On occasions I have applied stored procedures to the default database, when I meant to do it against another one on the server!

Another consequence is when a development database is refreshed or rebuilt from some external source (from a live environment, for example). Although your default database may exist by name, this is not enough for SQL Server, which fails to log you on and gives the error message:

Cannot open user default database.

You will also get this if you have chosen to rename the database.

So what to do in this instance?

Well, we can defer to the trusty ISQL command line utility, as shown in the following screenshot:

Simply follow these steps:

  1. Open a DOS  command Prompt
  2. Open up an ISQL Session. I used the following command:
    • -S SQLServer_Name – Specify the name of the SQL Server to which you are connecting.
    • -E – Stipulate to connect as a trusted connection (Windows Authentication)
    • -d master – The database name to which you are going to connect. Here I specified ‘master’
  3. isql -S SQLServer_Name -E -d master

    The three options user above are as follows:

    Of course, you can connect however you want. For more options (also shown in the screenshot above), type in isql /? for a full list, or refer to the site on the above link.

  4. Now run a version of the above script, setting the default database to master
  5. Exec sp_defaultdb @loginame='DOMAIN\UsrNam', @defdb='master';
  6. To apply this, enter ‘GO’ on the next line.

This will ensure your SQL Server defaults you to the ‘master’ database in all subsequent connections (unless you change them again). I would counsel this as general good practice, and it comes recommended by a friendly DBA I happen to know.

, , ,
Windows XP shutdown dialog box.
Image via Wikipedia

In the bad old days, when I wanted to shut down a remote Windows machine, I would log on through terminal services and then hit the ‘Turn Off’ button.

This carried the overhead of logging onto the computer manually, waiting for the settings to load and then clicking on the start men, etc, etc, etc.

Now we can just fire up cmd.exe and enter the following command:

shutdown -r -t 1 -m \\[computername]

In this instance we are specitying a restart of a remote machine, hence the -r and -m flags respectively.

For info, the spec for the command is below:

Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx]
                [-c "comment"] [-d up:xx:yy]
No args             Display this message (same as -?)
-i                  Display GUI interface, must be the first option
-l                  Log off (cannot be used with -m option)
-s                  Shutdown the computer
-r                  Shutdown and restart the computer
-a                  Abort a system shutdown
-m \\computername   Remote computer to shutdown/restart/abort
-t xx               Set timeout for shutdown to xx seconds
-c "comment"        Shutdown comment (maximum of 127 characters)
-f                  Forces running applications to close without warning
-d [u][p]:xx:yy     The reason code for the shutdown
                    u is the user code
                    p is a planned shutdown code
                    xx is the major reason code (positive integer less than 256)
                    yy is the minor reason code (positive integer less than 65536)

You could, of course type in shutdown /?

, , ,

By using the ping command line program, we can find ot the IP address of a given host and vice-versa, while, of course, testing whether we can communicate with this host:

Ping-pong
Image via Wikipedia

Pinging an IP address is easy:

ping 1.2.3.4

We can pinging the computer name for its IP:

ping Mycomputer

But how do we find out its name from its IP? Simply use the -a switch like so:

ping -a 1.2.3.4

As for the image? Well, everyone likes a bit of…ahem…ping-pong!
My apologies.
, , ,

Short and sweet and to the point. No graphics and no-nonsense.

  • Control Panel -> Programs and Features -> ”Turn Windows Features On Or Of”

(Command line option: Or type “OptionalFeatures.exe” in the Start-Menu (Windows button) ‘Start search’ box to achieve the same effect)

  • Check “Internet Information Services”
  • Wait. (It could well take a few minutes – the last time I did it, it took over 20! – you might think nothing is happening).

Job done!

, , ,

There have been a number of occasions recently where I have wanted to recompile, rename or delete a DLL, only to be thwarted by some locking problem:

I had no idea what was locking it.

My first investigations took me to this MSDN Blog Site. To summarise, you can utilise the little-known tasklist command-line interface. Typing tasklist /m thelocked.dll will list all processes that are locking your DLL.

Microsoft has also made available a tool that (probably) hooks into this. Process explorer provides a more visual overview of processes and dependencies. It’s also useful for tracking down DLL-version problems or handle leaks, and provide insight into the way Windows and applications work.

Screenshot of Unlocker 1.8.8
Image via Wikipedia

But the most useful tool for me by far was a tool called Unlocker. Upon installing the little application I was automatically prompted of processes that were locking a file when I get the access denied error.

So there we have it. A number of ways in which you can tackle this issue, and maybe even help extract yourself from DLL Hell!

, ,

Yesterday when wanting to run some commands from the Windows Command Shell, I fired it up on my windows XP desktop, only to find things were a little strange.

For a start it was slower – pasting something in from the clipboard seemed to take time. And then it didn’t protest too much when I started typing things I felt sure shouldn’t work. Then things I wanted to happen didn’t happen when I expected them to.

It all left me a bit confused.

And then I noticed, I’d typed in “command.com” not “cmd.exe”. I rectified the mistake, and everything seemed to be just fine. But I did wonder what the difference was.

Cmd or Command?

Well, initially, from the above screenshot we can see that the version information has the text is ‘Windows DOS’ vs ‘Windows XP’. However there are a number of other differences:

Cmd.exe is a command-line interface, provided so you can run command-line commands. It is not a DOS window.

Command.com is a stripped-down version of the command processor from DOS. It is a 16-bit application which is used for older DOS compatibility and actually runs inside the NTVDM (NT Virtual DOS Machine) due to its 16-bit nature.

With Command.com we do not have the long name support. Typing in ‘cd program files‘ yields the error ‘Too many parameters – files‘, whereas this command works fine in Cmd.exe. In fact to get this to work in Command.com, we have to type ‘cd progra~1‘.

,

After encountering a failure in a service that passed on emails to a mail server, my first point of investigation was to ensure the mailserver itself was functioning correctly.

So first things first, fire up your command shell window. Then start typing:

telnet Mailserver 25

>220 ServerName.domain Microsoft ESMPT MAIL Service, Version x.x.x.x ready at [time]

helo

>250 ServerName.domain.com Hello [IP]

mail from: me@domain.com

>250 2.1.0 me@domain.com....Sender OK

rcpt to:me@domain.com

>250 215 me@domain.com

data

>354 Start mail input; end with <CRLF>.<CRLF>

HELLO!
.                                             <–Press the dot button

>250 2.6.0. <ServerNameaaaAAA000bbbbbb111.domain.com> Queued mail for delivery

And,  hey presto! I got an email.

This determined that the culprit wasn’t the mail server, and I learned something new in the process. More info can be found at http://www.yuki-onna.co.uk/email/smtp.html

, ,

One thing I never quite realised before I started writing these post was just how reliant I was on command-line shortcuts. I have a growing number of posts on the various command line options I find useful.

cmd.exe, the DOS-styled command prompt used in...
Image via Wikipedia

Recently I’ve found myself having to launch various Windows control-panel applications, and have been finding it hassle to f ollow the various navigation links or icons. So I set about finding the shortcuts for the most common ones that I use.

Extensions given in square brakets are not requried (e.g. [.exe]), however are included to denote the type of application you are launching.

Service Control Manager: Services.msc

IIS Admin: inetmgr[.exe]

Event Viewer: eventvwr[.msc]

Add/Remove Programs: appwiz.cpl

System Properties - sysdm.cpl

This is also accessible by pressing windowsbutton-break

Terminal Services – mstsc[.exe]

There are more available on this website:

http://www.windowsnetworking.com/kbase/WindowsTips/Windows2003/AdminTips/Admin/LaunchingControlPanelAppsfromtheCommandLine.html

Enhanced by Zemanta