Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did SQL Server Management Studio 2008 command-line switches stop working?

I've always relied heavily on Windows shortcuts to SSMS that include command-line switches allowing me to quickly open up a specific database on a specific server. For example

Ssms.exe -S 123.123.123.123 -U sa -P goodpassword -d DbName

or

Ssms.exe -S . -E -d DbName

These suddenly stopped working. I get this error from SSMS:

Failed to create new SQL Server script.
Object reference not set to an instance of an object. (AppIDPackage)
Program Location: at Microsoft.SqlServer.Management.UI.VSIntegration.
AppIDPackage.AppIDPackage.OpenConnectionDialogWithGlobalConnectionInfo()

I can still launch SSMS without the command-line switches, and then manually establish the connections. Some command-line switches still work, for example

ssms.exe -nosplash

works fine.

I get the same error with any combination of the -S, -E, and -d command-line switches. It doesn't matter if I'm pointing to a valid server or database or not, or if my login credentials are good or not. I can point to the older version of SSMS and it works fine, but not the 2008 version.

This post on MSDN's forums is all I've found online, but MS hasn't been very helpful on this thread.

Any ideas how I might start to fix this? I work with a lot of different databases on different servers, and I really rely on these shortcuts.

like image 250
Herb Caudill Avatar asked Jul 20 '10 21:07

Herb Caudill


People also ask

How can I tell if SQLCMD is enabled?

You could try to execute sqlcmd.exe -? in a process in your C# app - if it works, then SQLCMD is present - if not, it'll tell you something like "file not found" or "command invalid" or something ....

How do I enable lines in SSMS?

Show/Hide Line Numbers in SSMS Click Tools–>Options as highlighted in green color below. In Options Dialog Box, Under Text Editor, in Transact-SQL, General –>Line Numbers . Enable the checkbox, If you want to Display/Show Line Numbers in SSMS. Disable the checkbox, If you want to Hide Line Numbers in SSMS.

Can you install SQLCMD without SQL Server?

Although it's probably too late for the original poster, for future reference, SQLCMD is freely downloadable, so it's not necessary to purchase SQL Server explicitly for this purpose.


1 Answers

I've thrown the DLL in question at reflector and it's given me back the code at the bottom of this post, sadly there's nothing immediately obvious in the code that makes it easy to work out why it's stopped working for you (wouldn't it be nice if Microsoft shipped debug symbols with anything they produce that's written against the CLR?).

There are a couple of places where the code makes me wonder if you might have a corrupted "recently used servers" list or something similar, perhaps you could try following the steps listed in this question to clear them out and see if that helps.

private void OpenConnectionDialogWithGlobalConnectionInfo()
{
    if ((ServiceCache.GlobalConnectionInfo != null) && (ServiceCache.GlobalConnectionInfo.Count != 0))
    {
        try
        {
            using (ConnectionDialog dialog = new ShellConnectionDialog())
            {
                IDbConnection connection;
                dialog.ImportRegisteredServersOnFirstLaunch = true;
                dialog.AddServer(new SqlServerType());
                UIConnectionInfo connectInfo = ServiceCache.GlobalConnectionInfo[0].Copy();
                if (dialog.TryToConnect(this.PopupOwner, ref connectInfo, out connection) == DialogResult.OK)
                {
                    this.ScriptFactory.CreateNewBlankScript(ScriptType.Sql, connectInfo, connection);
                }
            }
        }
        catch (Exception exception)
        {
            ExceptionMessageBox box = new ExceptionMessageBox(new ApplicationException(SRError.FailedToCreateNewSqlScript, exception));
            box.Caption = SRError.MessageBoxCaption;
            box.Show(this.PopupOwner);
        }
    }
    ServiceCache.GlobalConnectionInfo = null;
}
like image 188
Rob Avatar answered Sep 22 '22 03:09

Rob