如何在连接字符串adodb中添加用户名密码

时间:2019-07-15 12:25:16

标签: excel vba

我需要在ADODB连接中添加用户名和密码

With cn
    .ConnectionString = "DRIVER={SQL Server}; " & _
    " SERVER=MyServerName;" & _
    " DATABASE=db;" & _
    " Trusted_connection=YES"
    .Open
End With

1 个答案:

答案 0 :(得分:1)

这是查找可能的连接字符串的好资源:https://www.connectionstrings.com/sql-server/

您可以尝试例如:

With cn
    .ConnectionString = "DRIVER={SQL Server}; " & _
    " SERVER=MyServerName;" & _
    " DATABASE=db;" & _
    " User Id=myUsername;" & _
    " Password=myPassword"
    .Open
End With