0

I'm trying to do a little powerShell script, which establishes a OBDC connection using SQL Server Native Client 11.0 as Driver and retrieve some data which, in my case, is just getting the list to the database tables.

##### 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

The problem is when I run it, I get this problem

ERROR [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server] Could not find stored procedure 'show'

It seems like the problem comes from ExecuteReader but I can't find a way out, please help !

Salah Elgo
  • 85
  • 1
  • 2
  • 10
  • `"show tables;"` is a mysql syntax, is this a mysql or a mssql ? if is the last one the syntax is incorrect you can try `SELECT * FROM information_schema.tables` – CB. Sep 18 '15 at 11:57
  • True ! it seems like the problem was just a syntax problem! your query works fine ! thanks! – Salah Elgo Sep 18 '15 at 13:23

0 Answers0