Blog Post

Connection String Confusion in SSMS

,

Recently I was trying to use a connection string to connect in SSMS. There are some tools that have a connection string available as an output, including some Redgate tools. ADS lets me paste in a connection string. Can I do this in Management Studio (SSMS).

Yes, but be careful.

Getting a Connection String

There are lots of ways to get a connection string. You can build one, or use a site like https://www.connectionstrings.com/sql-server/ I tend to get them for applications, as I work more with app developers.

In any case, I’ll use this as my string:

Server=Aristotle;Database=Sandbox;Trusted_Connection=True;

If I open SSMs, I get a connection dialog like this one. I see the server, but if I wanted a specific database, I’d have to go to the second tab.

2024-09_0117

I could also go to the last tab, the Additional Connection Properties, and paste my string in there.

2024-09_0119

I press Connect and that works great.

2024-09_0120

If I open a new Query Window, I’m connected to the Sandbox database.

2024-09_0121

The Problem

Let’s change the connection. I’ll press the icon to the left of the database name in the image above. Then I’ll go to the second tab and pick a database. In this case, I’ve selected the Westwind database.

2024-09_0122

If I click Connect, I see this:

2024-09_0123

The connection string in the individual parameters overrides the selection here. If this were a day later, I might remember I’d put a string in the Additional Connection Parameters. I rarely use this and when this happened, I couldn’t figure out why this wasn’t working.

I thought this also happened with changing the main dialog and the server name, but this appears fixed. At least on SSMS 20.1, the additional connection parameters are linked with any saved systems I have on the first tab, so if I change servers in the drop down, the additional connection parameters link to the last entry for that server.

On my laptop, which has 20.2, I’ll enter this as a connection string in the last tab:

2024-09_0033

In this case, I have multiple container instances running on different ports. This instance is on port 41433. On the main tab of the connection dialog, I see this:

2024-09_0034

What happens when I press Connect? I get to this server:

2024-09_0035

The default port is SQL Server 2022, but the additional connection properties overrode the front screen in this case.

Summary

I’ve never had this problem in 30+ years of SQL Server work until this summer. However, it’s the first time I’ve really been focused on using connection strings more often than just entering values in the dialog. I only noticed this as I had a deployment going to one instance, but SSMS kept connecting to the other one and I didn’t realize this.

I think it’s OK to have conflicting values in locations, but it wasn’t clear to me that these values override others. This is documented on the MSLearn site, but it’s easy to miss this.

Hence this blog.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating