In PowerShell, goal is to query some data from Sql Server and put that into a preformatted Excel file. Towards that, the following PowerShell script snippet, throws an error saying "assemblies are missing".

From what I could gather online, SqlClient.SqlDataAdapter is part of ADO.Net, which does not require including any assemblies (as it is always present in the OS .Net framework installation). Is this correct? How do I rectify this?

... other connection code
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
$SqlCmd.Connection = $SqlConnection;
$SqlCmd.CommandText = $ActiveTransactions_Count_Query;

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
$SqlAdapter.SelectCommand = $SqlCmd;

$DataSet_ActiveTransaction = New-Object System.Data.DataSet;
$DataSetTable = $DataSet_ActiveTransaction.Tables[0];


New-Object : Cannot find type [Sql.Data.SqlClient.SqlDataAdapter]: make sure
the assembly containing this type is loaded.
At M:\Build.ps1:21 char:25 + $SqlAdapter = New-Object <<<< 
    + CategoryInfo          : InvalidType: (:) [New-Object],
    + FullyQualifiedErrorId :     TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

Put this at the top of your script:

Add-Type -AssemblyName System.Data

Yes it's part of the OS, and no this is not normally required, but there must be some issue from the combination of your OS version + PowerShell version + SQL 2008 R2.

  • If it helps,Windows Server 2008 R2 + Sql 2008 R2 + PowerShell Version 2 – ToC May 25 '16 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.