Skip to content
JaKson Note Logo JaKson Note Logo JaKson Note Logo
  • HD Tune

使用 PoweShell 連接 MSSQL

使用 PoweShell 連接 MSSQL

安裝 SqlServer 模組

Install-Module -Name SqlServer

程式碼

Import-Module -Name SqlServer

$serverName = “your_server_name”
$databaseName = “your_database_name”
$connectionString = “Server=$serverName;Database=$databaseName;Integrated Security=True”
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection($connectionString)
$connection.Open()

$query = “SELECT * FROM your_table_name”
$command = $connection.CreateCommand()
$command.CommandText = $query
$result = $command.ExecuteReader()

while ($result.Read()) {
$column1 = $result.GetValue(0)
$column2 = $result.GetValue(1)
# 輸出結果
Write-Host “Column1: $column1, Column2: $column2”
}

$connection.Close()

jakson2023-06-01T09:58:25+08:001 6 月, 2023|

分享至您的平台

FacebookTwitterRedditLinkedInWhatsAppTumblrPinterestVkEmail:

相關文章:

  • Last MSSQL Query

    24 2 月, 2025 | 0 條評論
  • 安裝 win11 Microsoft Photos

    8 2 月, 2025 | 0 條評論
  • Adobe 紅色視窗解決方式

    3 2 月, 2025 | 0 條評論

© Copyright 2021 Powered by JaKson

Go to Top