Powershell and SQL Connections

campbell1972
campbell1972 used Ask the Experts™
on
I am finding a discrepancy between Powershell ISE and Powershell running under the Administrator account.

My script contains a number of connections to SQL, all of which work without issue under ISE.

However, when executing from a Powershell prompt, a number of the SQL connections fail with the error: Exception calling Open with 0 argument(s): The ConnectionString property has not been initialized.

The code which is failing is as follows:

$connectionDB = New-Object System.Data.OleDb.OleDbConnection $connectionDetailsDB
$command22 = New-Object System.Data.OleDb.OleDbCommand $SQLConfigOptions, $connectionDB
$connectionDB.Open()

This format is used consistently throughout the script so the only difference appears to be the Powershell environment under which it executes.

As always, any pointers appreciated!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dan McFaddenSystems Engineer
Commented:
What is in the variable $connectionDetailsDB and $SQLConfigOptions?  The error "calling with 0 arguments indicates a variable could be empty.


Posting more of the script may help out...

Dan

Author

Commented:
Dan

I'll look to post some of the script later today.

However, how does this account for it running as expected under ISE?

JC
I'm pretty sure I've found the issue.

A closer look at the script and I can see that 'DB' has been transposed in some of the variable names.

Powershell ISE was blind to this and carried on regardless, even though the incorrect variables held no connection string details.

JC

Author

Commented:
Issue identified when parsing the file for unique variables

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial