Forum Discussion

noodles1030's avatar
noodles1030
Copper Contributor
Apr 09, 2024

The given value of type String from the data source cannot be converted to type nvarchar of the spec

Hi,

I am creating a date variable and attempting to write that variable to a SQL table. In my PS script, I do this:

 

$DateTime = $((Get-Date).ToString('yyyy-MM-dd-hh_mm_ss'))

 

I have tried setting the column in the SQL table to nvarchar(50), or varchar(50), and I still get this message:

 

System.InvalidOperationException: The given value of type String from the data source cannot be converted to type nvarchar of the specified target column.

 

Can someone give me some ideas on what to look for? I am going crazy with this 🙂

 

Thanks!

 

    • noodles1030's avatar
      noodles1030
      Copper Contributor

      olafhelper - I have changed that previously and it still will not work. If it is just a string and not datetime, why would that matter? 

      It is interesting - I can do the same thing with the same PowerShell script and write to a different table and it works. The column in the 2nd table is also nvarchar... any idea on that? 

      Thanks!

      • olafhelper's avatar
        olafhelper
        Bronze Contributor
        Can't say, you just posted one line of code, I don't know, what you do with the result in the rest.

Resources