Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQLServer与PowerShell的连接问题设置ConnectionTimeout属性_Sql Server_Powershell - Fatal编程技术网

Sql server SQLServer与PowerShell的连接问题设置ConnectionTimeout属性

Sql server SQLServer与PowerShell的连接问题设置ConnectionTimeout属性,sql-server,powershell,Sql Server,Powershell,我正在使用PowerShell连接到SQLServer数据库。我运行SQL代码的脚本工作正常,但它会周期性地无法生成所需的输出,然后再次运行 $mySQLQuery = "SQL Query Here" $myDataSet = New-Object System.Data.DataSet "myDataResultSet" $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=myDataSour

我正在使用PowerShell连接到SQLServer数据库。我运行SQL代码的脚本工作正常,但它会周期性地无法生成所需的输出,然后再次运行

$mySQLQuery = "SQL Query Here"

$myDataSet = New-Object System.Data.DataSet "myDataResultSet"
    $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=myDataSource;Initial Catalog=myDBServer;Integrated Security = False; User ID = UserName; Password =PassWord;")
    $SqlConn.ConnectionTimeout= 0
    $adapter = New-Object System.Data.SqlClient.SqlDataAdapter($mySQLQuery, $sqlConn)
$adapter.Fill($myDataSet)
$SqlConn.Close()
在搜索和阅读时,我发现这与连接超时有关。我尝试将sql连接超时从默认值30设置为0,但在运行scirpt时,出现如下错误:

$sqlConn.ConnectionTimeout = 0  is read-only property.
知道我做错了什么吗


谢谢。

解决此问题的最简单方法是添加
;连接超时=60
到您的连接字符串

$sqlConn = New-Object System.Data.SqlClient.SqlConnection('Connection Timeout=60')
$sqlConn.ConnectionTimeout
60

您可能不希望将其设置为0,如果需要一个高得离谱的值,请使用300或其他值。

解决此问题的最简单方法是添加
;连接超时=60
到您的连接字符串

$sqlConn = New-Object System.Data.SqlClient.SqlConnection('Connection Timeout=60')
$sqlConn.ConnectionTimeout
60
您可能不希望将其设置为0,如果需要一个高得离谱的值,请使用300或其他值。

我个人设置了命令超时,而不是连接

$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = "<yourconnectionstring>"

$command = $connection.CreateCommand()
$command.CommandText = "<yoursql>"
$command.CommandTimeout = 0

$results = $command.ExecuteReader()

$table = New-Object System.Data.DataTable
$table.Load($results)

$connection.Dispose()
$connection=New Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString=“”
$command=$connection.CreateCommand()
$command.CommandText=“”
$command.CommandTimeout=0
$results=$command.ExecuteReader()
$table=新对象System.Data.DataTable
$table.Load($results)
$connection.Dispose()
我个人设置命令超时,而不是连接

$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = "<yourconnectionstring>"

$command = $connection.CreateCommand()
$command.CommandText = "<yoursql>"
$command.CommandTimeout = 0

$results = $command.ExecuteReader()

$table = New-Object System.Data.DataTable
$table.Load($results)

$connection.Dispose()
$connection=New Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString=“”
$command=$connection.CreateCommand()
$command.CommandText=“”
$command.CommandTimeout=0
$results=$command.ExecuteReader()
$table=新对象System.Data.DataTable
$table.Load($results)
$connection.Dispose()

谢谢您尝试一下,看看效果如何。谢谢您尝试一下,看看效果如何。如果下面的建议不起作用,谢谢您尝试一下。感谢您的回复。如果下面的建议不起作用,我们将尝试这个方法。请告知你的答复。