我试图做一个小的powerShell脚本,它使用SQL Server Native Client 11.0作为驱动程序建立一个OBDC连接并检索一些数据,在我的例子中,这些数据只是将列表提供给数据库表。 / p>
##### Start the database connection and set up environment
$DbString="Driver=SQL Server Native Client 11.0;Server=[server_name];Database=[db_name];Uid=[user];Pwd=admin@[pwd];Encrypt=yes;Connection Timeout=30;"
$DBConnection=New-Object System.Data.Odbc.OdbcConnection
$DBCommand=New-Object System.Data.Odbc.OdbcCommand
$DBConnection.ConnectionString=$DbString
$DBConnection.Open()
$DBCommand.Connection=$DBConnection
$sqlQuery = "show tables;"
$DBCommand.CommandText = $sqlQuery
$DBCommand.ExecuterReader() //Crashes
问题是当我运行它时,我遇到了这个问题
ERROR [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server] Could not find stored procedure 'show'
似乎问题来自ExecuteReader,但我无法找到出路,请帮助!