不能让 powershell 使用指定的连接字符串来调用-sqlcmd

问题描述 投票:0回答:0

我设法创建了一个连接字符串,它使用只读连接,但我无法开始工作的是在 invoke-SQLCMD 中使用该字符串

   $conn = new-object System.Data.SqlClient.SQLConnection
$ConnectionString = "Server=AIAZEFMSQL03PRD,6295;Database=CKE;Application Name=Microsoft SQL Server Management Studio - Query;Integrated Security=True;Connect Timeout={3};ApplicationIntent=ReadOnly" -f $ServerInstance,$Database,$ApplicationName,$ConnectionTimeout
$conn.ConnectionString=$ConnectionString
$conn.Open()


$Gate = (Invoke-Sqlcmd -ConnectionString $ConnectionString -Query "
          
            Declare @CDAy varchar(20) =datename(dw,Getutcdate())
            ,@CHour int =  datepart(Hour,Getutcdate())

            Declare @Gate int  =  (

                        Select AT.Gate as TC

                        From [dbo].[AcquirerAlertThreshold] as AT
                        Where AT.Day = @Cday
                        and AT.Hour =@CHour
                   );

            IF @Gate IS NULL 
                BEGIN

                Select @Gate = 5
               ENd; 
    
"|Select -ExpandProperty  TC
)
sql powershell ssms
© www.soinside.com 2019 - 2024. All rights reserved.