1

Use DBUp DLL in PowerShell script to deploy SQL database scripts.

$databaseServer = $args['localhost\SQLEXPRESS']  
$databaseName   = $args['TestDatabase']
$scriptPath     =  $args['C:\Project\cLAWin\cla\Customers\Seagull\Dev\Joshua\Src\cLA\Database\Deliveries\PatchingScripts']

Add-Type -Path 'C:\RND\PWSEHLL\DbUp-master\DbUp-master\src\dbup-sqlserver\bin\Debug\netstandard2.0\dbup-sqlserver.dll'
Add-Type -Path 'C:\RND\PWSEHLL\DbUp-master\DbUp-master\src\dbup-core\bin\Debug\netstandard2.0\dbup-core.dll'

#[Reflection.Assembly]::LoadFrom('C:\RND\PWSEHLL\DbUp-master\DbUp-master\src\dbup-sqlserver\bin\Release\netstandard1.3\System.Data.SqlClient.dll')
#Add-Type -Path 'C:\RND\PWSEHLL\DbUp-master\DbUp-master\src\dbup-sqlserver'

$dbUp = [DbUp.DeployChanges]::To
$dbUp = [SqlServerExtensions]::SqlDatabase($dbUp,"server=$databaseServer;Database=$databaseName;Trusted_Connection=True;")
$dbUp = [StandardExtensions]::WithScriptsFromFileSystem($dbUp, $scriptPath)
$dbUp = [StandardExtensions]::LogToConsole($dbUp)

$upgradeResult = $dbUp.Build().PerformUpgrade()

I am using above line of code and getting below error message.

Upgrade failed due to an unexpected exception:
System.IO.FileNotFoundException: Could not load file or assembly
'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The system cannot find the file specified.
File name: 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a**'
   at DbUp.SqlServer.SqlConnectionManager.<>c__DisplayClass0_0.<.ctor>b__0(IUpgradeLog log, DatabaseConnectionManager dbManager)
   at DbUp.Engine.Transactions.DelegateConnectionFactory.CreateConnection(IUpgradeLog upgradeLog, DatabaseConnectionManager databaseConnectionManager)
   at DbUp.Engine.Transactions.DatabaseConnectionManager.CreateConnection(IUpgradeLog upgradeLog)
   at DbUp.Engine.Transactions.DatabaseConnectionManager.OperationStarting(IUpgradeLog upgradeLog, List`1 executedScripts)
   at DbUp.Engine.UpgradeEngine.PerformUpgrade()

Can you please assist me as I have above all version of .netcore SDKs.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Nitin Jain
  • 129
  • 1
  • 14
  • I pulished sqlserver (in DBup solution) project and using its bin folder dll. – Nitin Jain Oct 10 '19 at 08:27
  • 1
    Ran into a similar issue today today with DbUp (more than 2 years on), and noticed that with the current version of dbup (dbup-sqlserver, v.4.5.0), there is a dependency on multiple other nuget packages, including System.Data.SqlClient (>= 4.6.0). However, I'm abandoning this approach and will try the nuget package "dbup-cli" instead. – SimonAx Mar 05 '22 at 18:43

0 Answers0