Skip to content

Instantly share code, notes, and snippets.

@andrelashley
Created November 8, 2013 05:13
Show Gist options
  • Save andrelashley/7366562 to your computer and use it in GitHub Desktop.
Save andrelashley/7366562 to your computer and use it in GitHub Desktop.
Generate connection string in MSSQL server using query
elect
'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()
data source=ANDRE-PC;initial catalog=focussalessystems;trusted_connection=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment