I have a code which works fine without transaction
Yet, when I try to use code with transaction
<code>[void][system.reflection.Assembly]::LoadFrom("D:MySql.Data.dll")
$ConnectionString = "server=$MySQLServerAddress; port=$MySQLServerPort; database=$MySQLDatabase; uid=$MySQLUsername; pwd=$MySQLPassword;"
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection($connectionString)
$connection.Open()
$transaction = $connection.BeginTransaction()
try {
$command1 = $connection.CreateCommand()
$command1.CommandText = "INSERT INTO table1 (value1, value2) VALUES ('1366', 'jsjsjs')"
$command1.ExecuteNonQuery()
$transaction.Commit()
}
catch {
$transaction.Rollback()
Write-Host "Error during transaction: $($_.Exception.Message)"
}
finally {
$connection.Close()
}
</code>
<code>[void][system.reflection.Assembly]::LoadFrom("D:MySql.Data.dll")
$ConnectionString = "server=$MySQLServerAddress; port=$MySQLServerPort; database=$MySQLDatabase; uid=$MySQLUsername; pwd=$MySQLPassword;"
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection($connectionString)
$connection.Open()
$transaction = $connection.BeginTransaction()
try {
$command1 = $connection.CreateCommand()
$command1.CommandText = "INSERT INTO table1 (value1, value2) VALUES ('1366', 'jsjsjs')"
$command1.ExecuteNonQuery()
$transaction.Commit()
}
catch {
$transaction.Rollback()
Write-Host "Error during transaction: $($_.Exception.Message)"
}
finally {
$connection.Close()
}
</code>
[void][system.reflection.Assembly]::LoadFrom("D:MySql.Data.dll")
$ConnectionString = "server=$MySQLServerAddress; port=$MySQLServerPort; database=$MySQLDatabase; uid=$MySQLUsername; pwd=$MySQLPassword;"
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection($connectionString)
$connection.Open()
$transaction = $connection.BeginTransaction()
try {
$command1 = $connection.CreateCommand()
$command1.CommandText = "INSERT INTO table1 (value1, value2) VALUES ('1366', 'jsjsjs')"
$command1.ExecuteNonQuery()
$transaction.Commit()
}
catch {
$transaction.Rollback()
Write-Host "Error during transaction: $($_.Exception.Message)"
}
finally {
$connection.Close()
}
code fail with exception:
<code>Exception calling "BeginTransaction" with "0" argument(s):
"Could not load file or assembly "System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or one of its dependencies. The specified file was not found."
At line:31 char:1
$transaction = $connection.BeginTransaction()
Copy
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
Unable to call a method on a null-valued expression.
At line:52 char:5
Copy
$transaction.Rollback()
Copy
~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
</code>
<code>Exception calling "BeginTransaction" with "0" argument(s):
"Could not load file or assembly "System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or one of its dependencies. The specified file was not found."
At line:31 char:1
$transaction = $connection.BeginTransaction()
Copy
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
Unable to call a method on a null-valued expression.
At line:52 char:5
Copy
$transaction.Rollback()
Copy
~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
</code>
Exception calling "BeginTransaction" with "0" argument(s):
"Could not load file or assembly "System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or one of its dependencies. The specified file was not found."
At line:31 char:1
$transaction = $connection.BeginTransaction()
Copy
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
Unable to call a method on a null-valued expression.
At line:52 char:5
Copy
$transaction.Rollback()
Copy
~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [], RuntimeException
FullyQualifiedErrorId : InvokeMethodOnNull
There is now way I can obtain this “System.Runtime.CompilerServices.Unsafe” Method from MySQL.Data.dll
I just stuck and dunno what to do