Here I want to go to a folder where all my SQL files are and I want to run an SQL file */ );"; $DBCmd.ExecuteReader(); $DBConn.Close();
$result = (new-object data.odbc.OdbcCommand($db_query,$db_conn)).ExecuteReader() $table = new-object System.Data.DataTable $table.Load($result) 結果是數據列清單,代表從查詢擷取的使用者。 將結果寫入 CSV 檔案: PowerShell 複製 $out_filename = ".\users.csv" $table.Rows | Export-C...
[vchMessage] not like '%Setting database option ANSI_WARNINGS%' and [vchMessage] not like '%Error: 15457, Severity: 0, State: 1%' and [vchMessage] <> 'Error: 18456, Severity: 14, State: 16.' AND Logdate > GETDATE() - 2 DROP TABLE #Errors " $rdr = $sql.ExecuteReader() $dt...
1433;Initial Catalog=$Database;Persist Security Info=False;User ID=$Username;Password=$Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Pooling=True;Packet Size=8092"$connection=New-Object-TypeName System.Data.SqlClient.Sql...
$dbConn = new-object System.Data.SqlClient.SqlConnection "server=kcdb;database=Inventory;Integrated Security=sspi" $dbConn.Open() $sqlQuery = $dbConn.CreateCommand() # Get all known computers $sqlQuery.CommandText = "select * from Inventory..Computers" $reader = $sqlQuery.ExecuteRead...
$scriptcmd = New-Object System.Data.SqlClient.SqlCommand $scriptcmd.Connection = $scriptscon $scriptcmd.CommandText = $getscriptinfo $scriptcmd.CommandTimeout = 0 try { $scriptscon.Open() $scriptdetails = $scriptcmd.ExecuteReader() $scriptdatatable = New-Object System.Data.DataTable ...
$reader=$command.ExecuteReader() $reader.Read() Write-Host $reader.GetDateTime(0) $connection.Close() HTTP Copy This is a simple example to understand how to connect to an SQL Server database and perform any CRUD operation. But for more complex updates we need to also use transactions. We...
"@$command=$connection.CreateCommand()$command.CommandText =$query$result=$command.ExecuteReader()if($result.Read()){$currentSizeMB=$result.GetValue(0)$currentRows=$result.GetValue(1)$result.Close()return@{TotalSizeMB =$currentSizeMBTotalRows =$currentRows}}$re...
()$query = 'SELECT * FROM pg_catalog.pg_tables'$command = New-Object System.Data.Odbc.OdbcCommand($query,$conn)# For commands/queries that return rows$reader = $command.ExecuteReader() # Optionally, convert reader output to DataTable object for viewing # I disable constraints on my result...
$cmd = new-object System.Data.SqlClient.SqlCommand ($q, $sconn); $cmd.CommandTimeout = 0; $dr = $cmd.ExecuteReader(); while ($dr.Read()) { $ServerName = $dr.GetValue(0); $sqlQueryText = "select @@version" $selectResult=Invoke-Sqlcmd -ServerInstance $...