Powershell and SQL Connections

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!
campbell1972Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan McFaddenSystems EngineerCommented:
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
0
campbell1972Author 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
0
campbell1972Author Commented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
campbell1972Author Commented:
Issue identified when parsing the file for unique variables
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.