We help IT Professionals succeed at work.

Powershell and SQL Connections

campbell1972
campbell1972 asked
on
231 Views
Last Modified: 2017-04-04
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

Dan McFaddenTechnical Lead - Active Directory
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

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
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Issue identified when parsing the file for unique variables

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions