Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get the connection string for .NET and golang from the current MSSQL connection
-- part names via
-- prefer SSPI over True via
'Data Source=''' + @@servername + '''' +
';Initial Catalog=''' + db_name() + '''' +
case type_desc
then ';Integrated Security=SSPI'
else ';User ID=''' + suser_name() + ''';Password='''''
as DotNetConnectionString,
-- note the below need to be URI-encoded later on:
'sqlserver://' + suser_name() + ':password@' + @@servername + '/' + db_name() + '?param1=value&param2=value'
as GoLangConnectionString
-- sqlserver://username:password@host/instance?param1=value&param2=value
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