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

10,412

Solution 1

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;
}

Solution 2

The ObjectExplorer window must be open. Don't hide. I solved my problem this way :)

Share:
10,412
Herb Caudill
Author by

Herb Caudill

Herb is the founder and CTO of DevResults, a web app for managing foreign aid projects. DevResults is intended to make international development, grant-making, humanitarian assistance, and disaster relief programs more effective. It includes tools for monitoring & evaluation, mapping, project management, and collaboration.

Updated on July 20, 2022

Comments

  • Herb Caudill
    Herb Caudill almost 2 years

    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.

  • Herb Caudill
    Herb Caudill almost 14 years
    Good to know that it works for you. It was working for me until recently. According to MSDN msdn.microsoft.com/en-us/library/ms162825.aspx the same command-line switches should work for ssms.exe as worked for sqlwb.exe.
  • Herb Caudill
    Herb Caudill almost 14 years
    Here's the info from my About dialog: Microsoft SQL Server Management Studio 10.50.1600.1 Microsoft Data Access Components (MDAC) 6.1.7600.16385 Microsoft MSXML 3.0 4.0 5.0 6.0 Microsoft Internet Explorer 8.0.7600.16385 Microsoft .NET Framework 2.0.50727.4927 Operating System 6.1.7600
  • Herb Caudill
    Herb Caudill almost 14 years
    sqlwb.exe is SQL Server Management Studio 2005 - ssms.exe is 2008. I have 2005 installed but I'd prefer to use 2008.
  • Herb Caudill
    Herb Caudill almost 14 years
    Awesome - I followed the link to the question you mentioned, which brought me to this folder X:\Users\Herb Caudill\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell. I moved the various preference and settings files there to another folder, and was able to open SSMS normally. By selectively adding files back, I narrowed the problem down to the windows.prf file, which apparently had something in there that SSMS didn't like. I let it recreate that file & I'm back in business. Thanks!!
  • Rob
    Rob almost 14 years
    Glad I could be of help, to be honest I wasn't expecting this to answer the question for you, still, weyhey! :) Refletor, yet again, proves its worth.
  • Andrew Steitz
    Andrew Steitz over 12 years
    @Rob and Herb, I don't know why I am plagued with this problem but for me it is always when I try to register a server, I get the same type of message but with the "Program Location" set to the RegisteredServers. In the past I have ended up uninstalling SSMS and reinstalling. We all know how much fun that is. I used Herbs method and was able to clear it up. THANK YOU for saving me hours of time.
  • Sandip Armal Patil
    Sandip Armal Patil over 11 years
    This should look like comment... don't answered in one line. ;-)
  • Paul
    Paul about 11 years
    If the answer is truely 10 words then the Answer is 10 words.