6

I'm using SQL 2005, and was helping someone debug a connection issue today. I thought that I could view my current connection string from inside SQL Management Studio, but can't seem to figure out how to make it happen.

Is this possible? Google hunting has been fruitless.

Thanks!

3 Answers 3

1

You can't view your current SQL Management Studio connection string from within SQL Management Studio.

You could whip up your own connection string pretty quickly using the same details as when connecting to your SQL instance. Here's a resource with examples which might be helpful: http://www.connectionstrings.com/sql-server-2005

Hopefully I understood your question correctly...?

2
  • If you know for sure that I can't, then that's my answer. Finding a connection string isn't my issue - I just thought they'd have made it easy to see my current connection string in SSMS, like you can in Visual Studio. Odd.
    – Ducain
    Oct 5, 2010 at 1:12
  • 1
    This sucks. Why not? Mar 15, 2012 at 14:08
12

You can. From Stack Exchange:

SELECT
       'data source=' + @@servername +
       ';initial catalog=' + db_name() +
        case type_desc
           when 'WINDOWS_LOGIN' 
                then ';trusted_connection=true'
           else
                ';user id=' + suser_name()
        end
FROM sys.server_principals
WHERE name = suser_name()

2
  • Data Source / Server in Connection String != @@servername. Local host entries, SQL Client Aliases, and DNS mappings will all report something other than the what is in the Connection String. (Which is good, because none of those should change the nominative server [AD] + instance name, and also means that it can't be used to provide a guaranteed valid CS - ie, AD name might not be exposed - much less the actual CS..) Aug 11, 2018 at 1:14
  • This is incredibly frustrating. @@servername reports a server name that's different from the one I am connected to. Microsoft really made a hot pile of mess with something that should be simple and straightforward.
    – user148298
    Sep 25, 2021 at 18:00
0

this may be too late, but there seems to be a better answer for this question.

I was searching for the same thing; how do I view the connection string to a particular SQL Server database. I read you cannot do it within SQL Server Management Studio, but you can retrieve the connection string Visual Studio uses, as suggested by another user.

In Visual Studio, go to Server Explorer and choose to create a new connection by right clicking on Data Connections and browsing to the SQL Server to which you wish to connect. I am connecting to both SQL Server and MySQL so I would note this down for myself and others who might be in the same boat, so to speak.

When choosing a new Data Source, specify Microsoft SQL Server for your SQL connection, but MySQL needs a connector. You will need to have a MySQL/Oracle account to download the connector for MySQL.

http://dev.mysql.com/downloads/connector/net

Once this is installed, you will have an option of Oracle database when you are creating a new data connection for MysQL. You can now configure and connect to your data source and view the connection string for each data source. To do so, right click on the new Data Connection and select Properties. In the Connection String, you can copy and paste this for your Visual Studio connection string.

Again, since this came back in my search results, I am adding this note for myself in the future and possible others may find this useful.

Keenan

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .