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.
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.
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
db2lswtch -client -promote