Invalid cast from System.Data.SqlDbType to System.Data.DbType2019 Community Moderator ElectionIs it possible to open a Windows Explorer window from PowerShell?Load variables from another powershell scriptCan I cast in Powershell data section?Casting in powershell ? Weird syntax?How to run a Powershell script from the command line and pass a directory as a parameterERROR: Description = Invalid queryHow to open Powershell Console Window from PowershellHow to upgrade PowerShell version from 2.0 to 3.0Extract the filename from a pathPowerShell - Invalid cast from System.DateTime to System.ConsoleColor

What is "desert glass" and what does it do to the PCs?

Are Wave equations equivalent to Maxwell equations in free space?

Custom javascript not working

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

Convert an array of objects to array of the objects' values

How spaceships determine each other's mass in space?

What is Tony Stark injecting into himself in Iron Man 3?

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

What's the best tool for cutting holes into duct work?

When to use the term transposed instead of modulation?

Was it really inappropriate to write a pull request for the company I interviewed with?

Create chunks from an array

Professor forcing me to attend a conference

Too soon for a plot twist?

PTIJ: Aliyot for the deceased

Quitting employee has privileged access to critical information

Gemara word for QED

Should I use HTTPS on a domain that will only be used for redirection?

Giving a talk in my old university, how prominently should I tell students my salary?

Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?

Problems with rounding giving too many digits

I've given my players a lot of magic items. Is it reasonable for me to give them harder encounters?

Is it a Cyclops number? "Nobody" knows!

Remove object from array based on array of some property of that object



Invalid cast from System.Data.SqlDbType to System.Data.DbType



2019 Community Moderator ElectionIs it possible to open a Windows Explorer window from PowerShell?Load variables from another powershell scriptCan I cast in Powershell data section?Casting in powershell ? Weird syntax?How to run a Powershell script from the command line and pass a directory as a parameterERROR: Description = Invalid queryHow to open Powershell Console Window from PowershellHow to upgrade PowerShell version from 2.0 to 3.0Extract the filename from a pathPowerShell - Invalid cast from System.DateTime to System.ConsoleColor










0















I was writing a script to import cookies to google chrome.



On Powershell 3 my script works fine, but in Powershell 2 I have a problem when trying to insert a byte array. The error is:



Cannot convert argument "1", with value: "Binary", for "Add" to type "System.Data.DbType":
"Cannot convert value "Binary" to type "System.Data.DbType".
Error: "Invalid cast from 'System.Data.SqlDbType' to System.Data.DbType'.""
At C:UsersrootDesktopprocesshacker-2.39-bin1.ps1:90 char:22
+ $sql.Parameters.Add <<<< ("@encrypted_value", [System.Data.SqlDbType]"binary").value = $byte;


Script as follows:



Add-Type -AssemblyName System.Security #connect DPAPI

$parent_dll = $MyInvocation.MyCommand.Path | Split-Path -Parent
$sqlite_library_path = $parent_dll+"System.Data.SQLite.dll" #path to dll SQLite
[void][System.Reflection.Assembly]::LoadFrom($sqlite_library_path)

$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$path = Get-ChildItem "C:Users$env:usernameAppDataLocalGoogleChromeUser DataDefaultcookies" -Recurse

function decrypt_password ($enc_pass) % [byte] $_
$decrypt_char=[System.Security.Cryptography.ProtectedData]::protect($bytes, $null, [Security.Cryptography.DataProtectionScope]::LocalMachine) #

$encrypted_array = import-Csv -Path .c.txt
$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$con.ConnectionString = "Data Source=$path"
$con.Open()

foreach ($item in $encrypted_array)
$item.encrypted_value=decrypt_password -enc_pass $item
$sql = $con.CreateCommand();
$sql.commandtext = "INSERT INTO cookies (encrypted_value) VALUES (@encrypted_value)";
$sql.Parameters.Add("@encrypted_value", [System.Data.SqlDbType]"binary").value = [byte[]]$item.encrypted_value;
$fff=$sql.ExecuteNonQuery()
$sql.Dispose()


$con.Close()









share|improve this question









New contributor




josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please edit and update the question to a Minimal, Complete, and Verifiable example. As currently written, it's a bit unclear where the $byte variable comes from.

    – JosefZ
    yesterday











  • fixed. copied script wrong

    – josh brown
    yesterday






  • 1





    It's still not minimal. Reproduce the issue in 10 lines of code or less. Cut out everything that is not relevant.

    – Tomalak
    yesterday











  • Then, the error message should change as well, I guess…

    – JosefZ
    yesterday











  • removed unnecessary code. The main work goes in foreach block, rest is mainly setup and declarations

    – josh brown
    yesterday















0















I was writing a script to import cookies to google chrome.



On Powershell 3 my script works fine, but in Powershell 2 I have a problem when trying to insert a byte array. The error is:



Cannot convert argument "1", with value: "Binary", for "Add" to type "System.Data.DbType":
"Cannot convert value "Binary" to type "System.Data.DbType".
Error: "Invalid cast from 'System.Data.SqlDbType' to System.Data.DbType'.""
At C:UsersrootDesktopprocesshacker-2.39-bin1.ps1:90 char:22
+ $sql.Parameters.Add <<<< ("@encrypted_value", [System.Data.SqlDbType]"binary").value = $byte;


Script as follows:



Add-Type -AssemblyName System.Security #connect DPAPI

$parent_dll = $MyInvocation.MyCommand.Path | Split-Path -Parent
$sqlite_library_path = $parent_dll+"System.Data.SQLite.dll" #path to dll SQLite
[void][System.Reflection.Assembly]::LoadFrom($sqlite_library_path)

$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$path = Get-ChildItem "C:Users$env:usernameAppDataLocalGoogleChromeUser DataDefaultcookies" -Recurse

function decrypt_password ($enc_pass) % [byte] $_
$decrypt_char=[System.Security.Cryptography.ProtectedData]::protect($bytes, $null, [Security.Cryptography.DataProtectionScope]::LocalMachine) #

$encrypted_array = import-Csv -Path .c.txt
$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$con.ConnectionString = "Data Source=$path"
$con.Open()

foreach ($item in $encrypted_array)
$item.encrypted_value=decrypt_password -enc_pass $item
$sql = $con.CreateCommand();
$sql.commandtext = "INSERT INTO cookies (encrypted_value) VALUES (@encrypted_value)";
$sql.Parameters.Add("@encrypted_value", [System.Data.SqlDbType]"binary").value = [byte[]]$item.encrypted_value;
$fff=$sql.ExecuteNonQuery()
$sql.Dispose()


$con.Close()









share|improve this question









New contributor




josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please edit and update the question to a Minimal, Complete, and Verifiable example. As currently written, it's a bit unclear where the $byte variable comes from.

    – JosefZ
    yesterday











  • fixed. copied script wrong

    – josh brown
    yesterday






  • 1





    It's still not minimal. Reproduce the issue in 10 lines of code or less. Cut out everything that is not relevant.

    – Tomalak
    yesterday











  • Then, the error message should change as well, I guess…

    – JosefZ
    yesterday











  • removed unnecessary code. The main work goes in foreach block, rest is mainly setup and declarations

    – josh brown
    yesterday













0












0








0








I was writing a script to import cookies to google chrome.



On Powershell 3 my script works fine, but in Powershell 2 I have a problem when trying to insert a byte array. The error is:



Cannot convert argument "1", with value: "Binary", for "Add" to type "System.Data.DbType":
"Cannot convert value "Binary" to type "System.Data.DbType".
Error: "Invalid cast from 'System.Data.SqlDbType' to System.Data.DbType'.""
At C:UsersrootDesktopprocesshacker-2.39-bin1.ps1:90 char:22
+ $sql.Parameters.Add <<<< ("@encrypted_value", [System.Data.SqlDbType]"binary").value = $byte;


Script as follows:



Add-Type -AssemblyName System.Security #connect DPAPI

$parent_dll = $MyInvocation.MyCommand.Path | Split-Path -Parent
$sqlite_library_path = $parent_dll+"System.Data.SQLite.dll" #path to dll SQLite
[void][System.Reflection.Assembly]::LoadFrom($sqlite_library_path)

$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$path = Get-ChildItem "C:Users$env:usernameAppDataLocalGoogleChromeUser DataDefaultcookies" -Recurse

function decrypt_password ($enc_pass) % [byte] $_
$decrypt_char=[System.Security.Cryptography.ProtectedData]::protect($bytes, $null, [Security.Cryptography.DataProtectionScope]::LocalMachine) #

$encrypted_array = import-Csv -Path .c.txt
$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$con.ConnectionString = "Data Source=$path"
$con.Open()

foreach ($item in $encrypted_array)
$item.encrypted_value=decrypt_password -enc_pass $item
$sql = $con.CreateCommand();
$sql.commandtext = "INSERT INTO cookies (encrypted_value) VALUES (@encrypted_value)";
$sql.Parameters.Add("@encrypted_value", [System.Data.SqlDbType]"binary").value = [byte[]]$item.encrypted_value;
$fff=$sql.ExecuteNonQuery()
$sql.Dispose()


$con.Close()









share|improve this question









New contributor




josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I was writing a script to import cookies to google chrome.



On Powershell 3 my script works fine, but in Powershell 2 I have a problem when trying to insert a byte array. The error is:



Cannot convert argument "1", with value: "Binary", for "Add" to type "System.Data.DbType":
"Cannot convert value "Binary" to type "System.Data.DbType".
Error: "Invalid cast from 'System.Data.SqlDbType' to System.Data.DbType'.""
At C:UsersrootDesktopprocesshacker-2.39-bin1.ps1:90 char:22
+ $sql.Parameters.Add <<<< ("@encrypted_value", [System.Data.SqlDbType]"binary").value = $byte;


Script as follows:



Add-Type -AssemblyName System.Security #connect DPAPI

$parent_dll = $MyInvocation.MyCommand.Path | Split-Path -Parent
$sqlite_library_path = $parent_dll+"System.Data.SQLite.dll" #path to dll SQLite
[void][System.Reflection.Assembly]::LoadFrom($sqlite_library_path)

$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$path = Get-ChildItem "C:Users$env:usernameAppDataLocalGoogleChromeUser DataDefaultcookies" -Recurse

function decrypt_password ($enc_pass) % [byte] $_
$decrypt_char=[System.Security.Cryptography.ProtectedData]::protect($bytes, $null, [Security.Cryptography.DataProtectionScope]::LocalMachine) #

$encrypted_array = import-Csv -Path .c.txt
$con = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$con.ConnectionString = "Data Source=$path"
$con.Open()

foreach ($item in $encrypted_array)
$item.encrypted_value=decrypt_password -enc_pass $item
$sql = $con.CreateCommand();
$sql.commandtext = "INSERT INTO cookies (encrypted_value) VALUES (@encrypted_value)";
$sql.Parameters.Add("@encrypted_value", [System.Data.SqlDbType]"binary").value = [byte[]]$item.encrypted_value;
$fff=$sql.ExecuteNonQuery()
$sql.Dispose()


$con.Close()






powershell sqlite powershell-v2.0






share|improve this question









New contributor




josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Tomalak

260k52431548




260k52431548






New contributor




josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









josh brownjosh brown

11




11




New contributor




josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






josh brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Please edit and update the question to a Minimal, Complete, and Verifiable example. As currently written, it's a bit unclear where the $byte variable comes from.

    – JosefZ
    yesterday











  • fixed. copied script wrong

    – josh brown
    yesterday






  • 1





    It's still not minimal. Reproduce the issue in 10 lines of code or less. Cut out everything that is not relevant.

    – Tomalak
    yesterday











  • Then, the error message should change as well, I guess…

    – JosefZ
    yesterday











  • removed unnecessary code. The main work goes in foreach block, rest is mainly setup and declarations

    – josh brown
    yesterday

















  • Please edit and update the question to a Minimal, Complete, and Verifiable example. As currently written, it's a bit unclear where the $byte variable comes from.

    – JosefZ
    yesterday











  • fixed. copied script wrong

    – josh brown
    yesterday






  • 1





    It's still not minimal. Reproduce the issue in 10 lines of code or less. Cut out everything that is not relevant.

    – Tomalak
    yesterday











  • Then, the error message should change as well, I guess…

    – JosefZ
    yesterday











  • removed unnecessary code. The main work goes in foreach block, rest is mainly setup and declarations

    – josh brown
    yesterday
















Please edit and update the question to a Minimal, Complete, and Verifiable example. As currently written, it's a bit unclear where the $byte variable comes from.

– JosefZ
yesterday





Please edit and update the question to a Minimal, Complete, and Verifiable example. As currently written, it's a bit unclear where the $byte variable comes from.

– JosefZ
yesterday













fixed. copied script wrong

– josh brown
yesterday





fixed. copied script wrong

– josh brown
yesterday




1




1





It's still not minimal. Reproduce the issue in 10 lines of code or less. Cut out everything that is not relevant.

– Tomalak
yesterday





It's still not minimal. Reproduce the issue in 10 lines of code or less. Cut out everything that is not relevant.

– Tomalak
yesterday













Then, the error message should change as well, I guess…

– JosefZ
yesterday





Then, the error message should change as well, I guess…

– JosefZ
yesterday













removed unnecessary code. The main work goes in foreach block, rest is mainly setup and declarations

– josh brown
yesterday





removed unnecessary code. The main work goes in foreach block, rest is mainly setup and declarations

– josh brown
yesterday












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






josh brown is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55022520%2finvalid-cast-from-system-data-sqldbtype-to-system-data-dbtype%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








josh brown is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















josh brown is a new contributor. Be nice, and check out our Code of Conduct.












josh brown is a new contributor. Be nice, and check out our Code of Conduct.











josh brown is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55022520%2finvalid-cast-from-system-data-sqldbtype-to-system-data-dbtype%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко