Skip to content

Instantly share code, notes, and snippets.

@vadimblv
Last active February 23, 2023 13:06
Show Gist options
  • Save vadimblv/9d2b8fb6103c059341181cb0b18f8caf to your computer and use it in GitHub Desktop.
Save vadimblv/9d2b8fb6103c059341181cb0b18f8caf to your computer and use it in GitHub Desktop.
Get connection string from ms sql database
select
'data source=' + @@servername +
';initial catalog=' + db_name() +
case type_desc
when 'WINDOWS_LOGIN'
then ';trusted_connection=true;MultipleActiveResultSets=true'
else
';user id=' + suser_name() + ';password=<<YourPassword>>;'
end
as ConnectionString
from sys.server_principals
where name = suser_name()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment