Error When Running PowerShell Script with IBM.Data.DB2 Driver

Having just solved this problem for the second time in two weeks, I thought I’d blog about it to make it easier to find the next time.

Problem

This genereally occurs when you are executing a PowerShell script using the IBM.Data.DB2 driver on a server for the first time. It can also occur after patching of DB2 or the OS. Also, if you fail over from the HADR primary to the HADR standby, you may not have been executing PowerShell scripts on the standby regularly, so that is also a common time to see it. The error looks like this:

Exception calling "GetFactory" with "1" argument(s): "Unable to find the requested .Net Framework Data Provider.  It ma
y not be installed."
At db2_perf_maint.ps1:84 char:64
+ $factory = [System.Data.Common.DbProviderFactories]::GetFactory <<<< ("IBM.Data.DB2")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

This error leads to an error like this for every executed SQL statement in your script:

You cannot call a method on a null-valued expression.

Obviously there are other causes for that last one, but if you have a previously working script and you move it to a new server, this is one possible cause.

Solution

The solution is easy, and is described in this technote from IBM.

The jist of it is, all you have to do is open up a IBM DB2 Command window (not powershell command prompt) and issue one of the following:

db2nmpsetup -l c:\db2nmpsetup.log

or

db2lswtch -client -promote
Ember Crooks
Ember Crooks

Ember is always curious and thrives on change. She has built internationally recognized expertise in IBM Db2, spent a year working with high-volume MySQL, and is now learning Snowflake. Ember shares both posts about her core skill sets and her journey learning Snowflake.

Ember lives in Denver and work from home

Articles: 545

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.