Salah Elgo
Salah Elgo

Reputation: 85

OBDC and ExecuteReader issues

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 !

Upvotes: 0

Views: 537

Answers (0)

Related Questions