powershell MS SQL Powershell连接到SQL Server

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell MS SQL Powershell连接到SQL Server相关的知识,希望对你有一定的参考价值。

[string] $userName = "<userName>"
[string] $pwd = "<pwd>"
[string] $connStr = "Server=localhost;Database=master;
                     User ID=$userName;Password=$pwd;
                     Encrypt=false;TrustServerCertificate=False;
                     Connection Timeout=30;"

$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connStr
$connection.Open();

$cmd = $connection.CreateCommand()
$cmd.CommandText = "SELECT @@ServerName"

$reader = $cmd.ExecuteReader()
$reader.HasRows

$cmd.Dispose()
$connection.Close()

#Executing
# D:\PowershellScripts>& '.\PS Connecting to SQL Server.ps1'

以上是关于powershell MS SQL Powershell连接到SQL Server的主要内容,如果未能解决你的问题,请参考以下文章

Python 操作Redis

python爬虫入门----- 阿里巴巴供应商爬虫

Python词典设置默认值小技巧

《python学习手册(第4版)》pdf

Django settings.py 的media路径设置

Python中的赋值,浅拷贝和深拷贝的区别