gpt4 book ai didi

sql - 通过Powershell连接SQL Server(非本地)

转载 作者:行者123 更新时间:2023-12-02 23:17:10 27 4
gpt4 key购买 nike

我正在尝试使用PowerShell连接到远程SQL Server实例。
我的用户名是ONE_PERSON
这是我正在使用的代码:

$user = "ONE_PERSON" 
$connectionString = "Server=$dataSource; uid=$user; pwd=$pwd; Database=$database; Integrated Security = False;"
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$connection.Open()
当我运行它时,我得到一个错误

Login failed for user 'ONE_Person'


由于某种原因,即使我自己运行 $user,它也会将用户切换为小写字母,但仍以大写 ONE_PERSON显示给我。
我什至尝试通过在末尾使用 .ToUpper强制其保持大写
和见解将不胜感激

最佳答案

$ pwd是PowerShell中的保留路径变量。尝试将变量另存为$ password之类的值,然后查看是否可行。

关于sql - 通过Powershell连接SQL Server(非本地),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62526119/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com