尝试以其访问权限禁止的方式访问套接字

mi7gmzs6  于 2021-08-13  发布在  Java
关注(0)|答案(0)|浏览(226)

我这里的情况真的很令人沮丧。有一个powershell脚本可以登录到azure sql,查询表,并将结果保存到.csv文件中。连接字符串如下所示:

$DatabaseUrl = "mycompany-***-***-dev-use4-01.database.windows.net"
$DatabaseName = "MyDataBase"
$conn = New-Object System.Data.SqlClient.SQLConnection 
$conn.ConnectionString = "Data Source=$DatabaseUrl;Initial Catalog=$DatabaseName;Connect Timeout=20"
$conn.AccessToken = $token
$conn.Open

$conn.Open 脚本抛出此错误的行:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - An
attempt was made to access a socket in a way forbidden by its access permissions

现在,当这个脚本在powershell ise中运行得非常好,但在powershell cli(命令行)中运行得不好时,就会遇到挫折。到目前为止,我已经搜索了数百万个帖子,仍然没有找到任何解决方案。我试着以管理员的身份运行cli Import-Module -SQLServer -Scope CurrentUser 和其他人。老实说,我完全不知道为什么脚本可以在ise中工作,但不能在cli中工作。这两种环境/脚本语言不同吗?谢谢你的帮助

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题