8

I'm connected to database. I use db by Management Studio 2012 Express. Can I check connection string by click something in Management Studio?

11

Within SSMS, I'm not sure there's an easy way to do that. But a simple query will return you the information (without the password of a connection string, obviously):

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()

Note, db_name() will return the current database name if there is no parameter specified, so that is dependent on your current scope.

  • just for info: in SSMS 2010, the view sys.server_principals doesn't exist yet. But we can use the table syslogin (if I recall correctly) – Hoàng Long Oct 1 '15 at 5:54
  • I am new to SSMS. I created a new query with above code and ran it. It says "query executed successfully" but where would I find actual the results? Output window only shows "app exited with error code 0". – jj_ Jun 13 '18 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.