2017-09-01 72 views
0

我的操作系統是Windows 10,我使用PowerShell來嘗試創建一個DSN條目 這是我用過的命令:SetPropertyValue在不承認PowerShell中

Add-OdbcDsn -Name MyTest2 -DriverName "SQL Server Native Client 11.0" -DsnType System 
    -SetPropertyValue @("Server=MyServer", "Description=My second Test","User=MyTestUser","Password=12345", "Database=MyTestDB") 

DSN的條目被創建,但我得到這個錯誤:

-SetPropertyValue : The term '-SetPropertyValue' is not recognized as the name of a cmdlet, function, script file, or 
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At line:2 char:5 
+  -SetPropertyValue @("Server=MyServer", "Description=My se ... 
+  ~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (-SetPropertyValue:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

請告知我的聲明中出現了什麼問題,如果可能的話如何解決?

更新:

我加入了2線

Add-OdbcDsn -Name MyTest3 -DriverName "SQL Server Native Client 11.0" -DsnType System -Platform '32-bit' -SetPropertyValue @("Server=MyServer", "Description=My second Test","User=MyTestUser","Password=12345", "Database=TestDB") 

,我得到這個錯誤:

Add-OdbcDsn : Invalid keyword-value pairs (Installer error code: 8). 
At line:1 char:1 
+ Add-OdbcDsn -Name MyTest3 -DriverName "SQL Server Native Client 11.0" ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (MyTest2 (32-bit ODBC System DSN):Root/Microsoft/...SFT_OdbcDsnTask) [Add-OdbcD 
    sn], CimException 
    + FullyQualifiedErrorId : MI RESULT 0,Add-OdbcDsn 

Add-OdbcDsn : Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed (Installer error code: 11). 
At line:1 char:1 
+ Add-OdbcDsn -Name MyTest3 -DriverName "SQL Serv 
+2

參數不會自動連接到上一行,因此您需要'在上一行的末尾。 [如何輸入多行命令?](// stackoverflow.com/q/3235850) – wOxxOm

+0

我明白了......謝謝!我在一行中加入了它們,但是我仍然遇到了錯誤...請參閱我的更新 – user1205746

+0

我剛剛更新了一行中的所有內容 – user1205746

回答

3

你更新後的問題是關鍵的用戶名和密碼不被識別爲一個SQL連接字符串。

將它們更新到"Uid=MyTestUser","Pwd=12345"它應該工作。

更多信息可在connectionstrings.com找到。

+0

你能爲我澄清一下嗎?你是說我需要分兩步來做:首先創建沒有uid和pwd的條目,然後用uid和pwd再次使用set_odbcdsn和-SetPropertyValue更新新添加的條目? – user1205746

+0

這是我得到的錯誤:嘗試設置DSN的{UID或PWD}鍵。這些密鑰不應該存儲在註冊表中以保證安全 的原因。我無法設置uid和pwd。不知道你是如何做到的。請指教。 – user1205746