2011-09-15 21 views
5

以下のpowershellスクリプトを使用して、SQL Serverのインスタンスに接続しています。私はかなり私のユーザー名とパスワードが正しいと確信しています。powershellを使用してSQL Serverに接続します。

$ connectionString = "サーバー= {0};データベース= {1}; uid = {2}; pwd = {3};"

$c = Get-Credential 
Write-Host($ipAddress) 
Write-Host $c.username 
Write-Host $c.GetNetworkCredential().password 

$connectionString = [string]::Format("server={0};database={1};uid={2};pwd={3};", "servername", "databasename",$c.username,$c.GetNetworkCredential().password) 
#open database connection to SQL Server 

Write-Host $connectionString 
$conn = New-Object system.Data.SqlClient.SqlConnection 
$conn.connectionstring = $connectionString 
$conn.open 

    switch ($conn.State) 
{ 
"Open" { Write-Host "Do some work"; } 
Default { Write-Host "The connection is $($conn.State). There has been an error connecting to the database."; } 
} 

それは常にデフォルトのステートメントに落ちています。

答えて

4

$ conn.openの呼び出しに()がないため、そのメソッドを呼び出すのではなくそのメソッドへの参照が返されます。

+0

ありがとうございます。あなたはそれを釘付け..... – Gagan

関連する問題