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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved