Tag: syndicated

  • 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.

  • Small Data SF 2024

    I have often made an effort to attend conferences in the past to grow my career. Even today, when I speak at a conference, I’ll try to go to a few sessions and learn something, but I can be distracted. It’s rare I focus on just learning stuff without other responsibilities.

    I’m at Small Data today and tomorrow doing precisely that. I’m just an attendee, and today is a couple of workshops for me with a variety of talks tomorrow. It’s a real career growth opportunity for me and I’m excited. I’m doing the Data Warehousing and Design workshops today and sitting in sessions all day tomorrow.

    I can’t remember where I heard of this conference, but when I saw the manifesto and sessions, I was intrigued. There were tentative plans this week for me to do a customer visit, but when that got delayed, I jumped on the opportunity to visit San Fran and learn something.

    As I’ve worked with a lot of customers, I see the value of small data sets providing lots of agility for teams, while also allowing them to get work done, as long as the data sets are relevant and representative. That’s a big part of me pushing the Subsetter at Redgate.

    In this case, the conference focuses more on analytics and AI, and likely more developers than DBAs, but I think it’s a chance to get different perspectives, maybe learn a few things, and perhaps get others to see my data viewpoint in the hallways discussions.

  • A New Word: Mottleheaded

    mottleheaded – adj. feeling uneasy when socializing with odd combinations of friend and family, or friends and colleagues, or colleagues and family – mixing a medley of ingredients that don’t typically go together, which risks either watering down your identity into gray much or accidentally triggering some sort of explosion.

    Mixing groups of people from different situations has sometimes been a struggle for me. I’ve felt quite mottleheaded at times when I have people I work with in coaching, at Redgate, and from friends/neighbors/family. It seems that they can be very different people.

    I’m sure I’m overthinking this, but I’ve rarely invited different groups of people to the same place, precisely because I do worry that someone might not enjoy the time with those others. I know I’ve felt awkward at times at horse-related things for my wife. I don’t mind and am happy to support her, even if it’s strange for me.

    From the Dictionary of Obscure Sorrows

  • Parsing EXE Output in PowerShell

    I saw a post internally that asked this question: Anyone have a handy powershell script testing if the installed flyway version matches a specific string?

    That seemed simple, but getting program output from PoSh wasn’t something I’ve tried. So I tackled the challenge and this is what happened.

    Getting the Output

    The first thing I wanted to do was actually figure out what the output of checking the version was from the CLI. I looked at the help and noticed a version verb. When I run that, I see a bunch of lines of output.

    2024-09_0002

    A lot of output. I need to parse a bunch of strings, and then find a line.

    My first experiment was to run this to get a file with this output.

    flyway version > fwversion.txt

    Now, let’s parse this.

    Parsing Content

    It’s been awhile since I read stuff from a file, but I know Get-Content works to read the file. What about finding a line. I saw this post with an answer that noted Select-String can be used, so I decided to try that.

    Here’s a first cut of code:

    2024-09_0003

    That didn’t work. However, with some experiments, I tried this code:

    Get-content fwversion.txt | select-string 'Edition'

    That worked.

    2024-09_0004

    Now, I’ll assign that to a variable with this code:

    $a=Get-content fwversion.txt | select-string ‘Edition’

    Next, I’ll split this string by spaces into a new variable with this:

    $b = $a -split(‘ ‘)

    Then I can evaluate the various element of $b. You can see below the first and third elements are what I’m interested in. Really the third. Remember, PoSh is zero-based.

    2024-09_0005

    That let’s me parse the output, but I don’t want to save a file. Now on to the next step.

    Capturing the Output from a Program

    One of the things I know you can do in a PoSh ptompt is run a program. The redirection operator allows you to move output. When I tried it, I couldn’t quite get the output I wanted, but I did find this post that helped. With that, I ran this code:

    $a = & "flyway" --version  2>&1 | select-string 'Edition'

    This runs Flyway, captures the output in a stream and then uses the code above to find the right line. I assign this to a variable.

    Almost there.

    Adding a Parameter and a Test

    Since I want to call this from the CLI and pass i a parameter, I added a param() clause to my script and then a test that compares the version output from the flyway.exe to the parameter. That gest me this code:

    param(
        [string]$versionToCheck=""
    )
    $a = & "flyway" --version  2>&1 | select-string 'Edition'
    $b = $a -split(' ')
    if ($b[3] -eq $versionToCheck)
    { Write-Output("$($b) installed")}
    else {

    Write-Output(“wrong version – $($b) installed”)
    }

    
    

    Now I can call this from the CLI and check things. It works well. At least for now.

    2024-09_0001

    I am certainly not a PoSh expert, but this short script took me about 15 minutes to write with a little research. Then a little testing and I sent it off to the requester. Haven’t heard any complaints, so I’m hoping this actually works for them.