用SQL Server(T-SQL)获取连接字符串
时间:2021-07-01 10:21:17
帮助过:25人阅读
SELECT ‘server=‘
2 + CONVERT(
NVARCHAR(
40),
ISNULL(CONNECTIONPROPERTY(
‘local_net_address‘),
‘.‘))
3 + CASE WHEN CONNECTIONPROPERTY(
‘local_tcp_port‘)
IS NULL THEN ‘‘ ELSE ‘,‘ END
4 + CONVERT(
NVARCHAR(
40),
ISNULL(CONNECTIONPROPERTY(
‘local_tcp_port‘),
‘‘))
+ ‘;database=‘ + DB_NAME()
5 + CASE type_desc
6 WHEN ‘WINDOWS_LOGIN‘ THEN ‘;trusted_connection=true‘
7 ELSE ‘;uid=‘ + SUSER_NAME()
+ ‘;pwd=yourpassword‘
8 END
9 FROM sys.server_principals
10 WHERE name
= SUSER_NAME()
用SQL Server(T-SQL)获取连接字符串
标签: