Trying out Octopus deploy for the first time. Trying to deploy a dacpac to a machine and it keeps on failing. I keep on getting the following error:
Exception calling "Extract" with "4" argument(s): "Could not connect to database server."
At C:\Octopus\Work\20191023152506-102-81\Script.ps1:394 char:13
+ $dacServices.Extract($dbDacPacFilepath, $TargetDatabase, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : DacServicesException
The remote script failed with exit code 1
The action SQL - Deploy DACPAC on Staging failed
I am currently using SQL server 2017 and have the dacframework installed for SQL server 2016. for the connection string i tried using ., localhost, and the name of the server given in sql management studio. I am not passing any credentials, I am using integrated security. I am also passing the database name as well.
I followed this youtube video also, just without using the project variables.
In my previous experience I just used the SqlPackage.exe to deploy a dacpac. Helps for manually testing and polishing out permissions, or other issues.
For example:
#example usage:Generate-DBUpdate-Script -server $dbServer -db $dbName -user $dbUser -psw $dbPassword -dacpacFilePath $dacpacFile -publishProfilePath ".\Publish\$dbPublishProfile" -outputFile $SqlUpgradeArtifactName
function Generate-DBUpdate-Script($server, $db, $user, $psw, $dacpacFilePath, $publishProfilePath, $outputFile)
{
#generate an update script
& 'C:\Program Files (x86)\Microsoft SQL Server\110WorkingDAC\DAC\bin\SqlPackage.exe' /Action:Script /OutputPath:$outputFile /SourceFile:$dacpacFilePath /Profile:$publishProfilePath /TargetServerName:$server /TargetDatabaseName:$db /TargetUser:$user /TargetPassword:$psw
#save generated script as deployment artifact
New-OctopusArtifact $outputFile
}
Can change the action to publish to avoid generating the script and just deploy straight away.
Hope that helps.
Related
Trying to Import SQL Server module to use Invoke-Sqlcmd and whether in raw PowerShell ISE (as Administrator and non-Admin) or via SSMS I get the same error and wondering if someone could help please?
The version I am using is an unzipped nupkg of sqlserver.21.1.18230 (the latest release) and the DLL's are in the right location (C:\Program Files\WindowsPowerShell\Modules). The DLL's are not showing as Blocked in the Properties. Security is showing "Full Control" on the DLL in the Properties.
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select PSChildName, Version, Release
##Get PowerShell version
$PSVersionTable
$Env:PSModulePath
#Get-PSRepository
Get-ExecutionPolicy -List
[Environment]::Is64BitProcess
Import-Module SqlServer
The Import-Module is failing with the following results (after the error a raft of other DLL's from the SqlServer.psm1 script are listed also erroring)
PSChildName Version Release
----------- ------- -------
v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.8.03752 528040
Full 4.8.03752 528040
Client 4.0.0.0
C:\Users\app-itsme\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\windows\system32\WindowsPowerShell\v1.0\Modules
Import-Module : Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\SqlServer\Microsoft.SqlServer.Management.PSSnapins.dll' or one of its dependencies. Operation is not
supported. (Exception from HRESULT: 0x80131515)
At C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psm1:61 char:25
+ ... $binaryModule = Import-Module -Name $binaryModulePath -PassThru
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
The variable '$binaryModule' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psm1:63 char:29
+ $importedModules += $binaryModule
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (binaryModule:String) [], RuntimeException
+ FullyQualifiedErrorId : VariableIsUndefined
Any help appreciated
Thank you
The issue was still around permissions and installation. Installation seemed to have to be at non-admin and then Install-Module at non-admin. It was then available as admin.
Also the Powershell admin doesnt have internet access something that Powershell assumes always exists which added to the woes of other solutions being attempted. Had to set proxy firewall etc
Thanks
I have a powershell script that I need to execute from a SQL server on a schedule. I don't think it matters, but in case it does, the script is sending the command to refresh a powerbi.com dataset. I can run it successfully locally and on one of my servers, but when I try it on the other one, I get the error below.
For clarification, the powershell versions match as well as the execution policies. I have listed them here:
PS Version 5.1.14409.1005
Execution Policy
Scope ExecutionPolicy
Machine Policy Undefined
User Policy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
The error I get on one of the servers is below:
Connect-PowerBIServiceAccount : Failed to populate environments in settings
At
DatasetRefresh_NoParam_Simple.ps1:9
char:1
+ Connect-PowerBIServiceAccount -Credential $myCred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-Po
werBIServiceAccount], Exception
+ FullyQualifiedErrorId : Failed to populate environments in settings,Microsoft.PowerBI.Commands.Profile.ConnectPo
werBIServiceAccount
Invoke-PowerBIRestMethod : Login first with Login-PowerBIServiceAccount
At
DatasetRefresh_NoParam_Simple.ps1:19
char:1
+ Invoke-PowerBIRestMethod -Url $RefreshDSURL -Method Post -Body $MailF ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-PowerBIRestMethod], Exception
+ FullyQualifiedErrorId : System.Exception,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
I feel like there is a server setting that I'm missing, but I'm logged into both with admin credentials and running powershell as administrator. Any help would be appreciated.
EDIT
I tried to run a different script to also show the other error I am getting.
\\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_PS\DatasetRefresh_Param_onlyDataset.ps1 : File
\\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_PS\DatasetRefresh_Param_onlyDataset.ps1 cannot be
loaded. The file
\\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_PS\DatasetRefresh_Param_onlyDataset.ps1 is not
digitally signed. You cannot run this script on the current system. For more information about running scripts and
setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ \\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
This is the one I got too that led me to look at the execution policies, but if both of my servers have the same policy settings, why am I able to execute on one and not the other? (Again, I'm logged in as myself on both with admin privileges)
If you are executing it from SQL Server - I assume that is using SQL Agent?
Be aware of the context that SQL Server Agent executes in - have you created a SQL Agent Proxy using a defined credential to ensure the context?
I am currently trying to execute the command
add-sqlsnappin
which give me error message
SQL Server Provider for Windows PowerShell is not installed.
At C:\deploy\SIF.Sitecore.Commerce.1.1.4\Modules\DeployCommerceDatabase\DeployCommerceDatabase.psm1:215 char:9
+ throw "SQL Server Provider for Windows PowerShell is not inst ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (SQL Server Prov... not installed.:String) [], RuntimeException
+ FullyQualifiedErrorId : SQL Server Provider for Windows PowerShell is not installed.
Which cannot be true since
if (Get-Module -ListAvailable -Name SqlServer) {
>> Write-Host "Module exists"
>> } else {
>> Write-Host "Module does not exist"
>> }
Module exists
so why can i not add-sqlsnapin?
The sqlserver module and SQL Server snap-in aren't the same thing. So, the module existing doesn't mean the snap-in is registered in-order for you to load it. Give the Running SQL Server PowerShell on MSDN a look. If you want the SqlServer module, try the following:
Import-Module sqlserver
I'm trying to use a "Deploy SSIS" task in VSTS. I get this error:
Task_InternalError Exception calling ".ctor" with "1" argument(s): "Failed to connect to server xyz
It is asking for the following information below. How do I go about finding the information below needed for this task? The path to the .ispac file is easy since it is uploaded. I also think the name of the server is correct.
-Display name
-Path to .ispac file
-Name of the SSIS project in the .ispac file
-Name of the SQL Server hosting the SSIS catalog database
-Name of the SSIS catalog
-Name of the SSIS catalog folder
-Description of the SSIS catalog folder
Edit:
(detailed error log)
2017-09-20T12:55:05.6438379Z ##[debug]Env:INPUT_PROJECTFILEPATH: 'd:\a\3\s\HR Data.ispac'
2017-09-20T12:55:05.6468345Z ##[debug]Env:INPUT_PROJECTNAME: 'xyz'
2017-09-20T12:55:05.6488487Z ##[debug]Env:INPUT_SERVERNAME: 'xyz'
2017-09-20T12:55:05.6538355Z ##[debug]Env:INPUT_CATALOGNAME: 'xyz'
2017-09-20T12:55:05.6558353Z ##[debug]Env:INPUT_FOLDERNAME: 'xyz'
2017-09-20T12:55:05.6568351Z ##[debug]Env:INPUT_FOLDERDESCRIPTION (empty)
2017-09-20T12:55:05.6618490Z ##[debug]Env:INPUT_PROJECTPARAMETERS (empty)
2017-09-20T12:55:05.6628342Z SQL Connection String: Data Source=xyz;Initial Catalog=master;Integrated Security=SSPI;
2017-09-20T12:55:05.6638360Z Project file path: d:\a\3\s\xyz.ispac
2017-09-20T12:55:22.8057049Z ##[debug]Leaving D:\a_tasks\DeploySsis_582498ad-81d6-48b7-b9bc-fd0e5dec2e2b\0.1.0\DeploySSISTask.ps1.
2017-09-20T12:55:22.8388650Z ##[debug]Caught exception from task script.
2017-09-20T12:55:22.8418679Z ##[debug]Error record:
2017-09-20T12:55:22.8948708Z ##[debug]D:\a_tasks\DeploySsis_582498ad-81d6-48b7-b9bc-fd0e5dec2e2b\0.1.0\DeploySSISTask.ps1 : Task_InternalError Exception calling ".ctor" with "1" argument(s): "Failed to connect to server xyz."
2017-09-20T12:55:22.8968708Z ##[debug]At line:1 char:1
2017-09-20T12:55:22.8978718Z ##[debug]+ . 'd:\a_tasks\DeploySsis_582498ad-81d6-48b7-b9bc-fd0e5dec2e2b\0.1.0\ ...
2017-09-20T12:55:22.8988697Z ##[debug]+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-09-20T12:55:22.8998697Z ##[debug] + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
2017-09-20T12:55:22.9008861Z ##[debug] + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,DeploySSISTask.ps1
2017-09-20T12:55:22.9018704Z ##[debug]
2017-09-20T12:55:22.9048688Z ##[debug]Script stack trace:
2017-09-20T12:55:22.9078699Z ##[debug]at ,
D:\a_tasks\DeploySsis_582498ad-81d6-48b7-b9bc-fd0e5dec2e2b\0.1.0\DeploySSISTask.ps1: line 97
2017-09-20T12:55:22.9098691Z ##[debug]at , : line 1
2017-09-20T12:55:22.9108747Z ##[debug]at , : line 22
2017-09-20T12:55:22.9118883Z ##[debug]at , : line 18
2017-09-20T12:55:22.9128882Z ##[debug]at , : line 1
2017-09-20T12:55:22.9148698Z ##[debug]Exception:
2017-09-20T12:55:22.9188799Z ##[debug]Microsoft.PowerShell.Commands.WriteErrorException: Task_InternalError Exception calling ".ctor" with "1" argument(s): "Failed to connect to server xyz."
2017-09-20T12:55:22.9478706Z ##[error]Task_InternalError Exception calling ".ctor" with "1" argument(s): "Failed to connect to server xyz."
2017-09-20T12:55:22.9478706Z ##[debug]Processed: ##vso[task.logissue type=error]Task_InternalError Exception calling ".ctor" with "1" argument(s): "Failed to connect to server xyz."
2017-09-20T12:55:22.9508700Z ##[debug]Processed: ##vso[task.complete result=Failed]
Regarding Deploy SSIS task, it connects to the server with windows authentication (Integrated Security=SSPI), but the Hosted agent uses service account that can’t connect to the server.
You can set up a private build agent (running as your account) and queue build with that build agent, or you can refer to the source code to build the PowerShell script to deploy SSIS project with SQL Server authentication (User ID=XXX; Password=XX)
A related thread: Build and Deploy SSIS packages using VSTS
I have VS2015 with SSDT installed, along with SSMS and the SqlServer PowerShell module (which includes the invoke-sqlcmd comand), and yet If I try to execute a query against an Azure SQL Data Warehouse like so:
invoke-sqlcmd -Query "Select top 5 * from customer" -ConnectionString "Server=tcp:my.database.windows.net,1433;Database=Customer; Authentication=Active Directory Integrated; Encrypt=True; "
I get the following error:
invoke-sqlcmd : Unable to load adalsql.dll (Authentication=ActiveDirectoryIntegrated). Error code: 0x2. For more information, see
http://go.microsoft.com/fwlink/?LinkID=513072
At line:1 char:1
+ invoke-sqlcmd -Query "Select top 5 * from vwOffer" -ConnectionStrin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
+ FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
invoke-sqlcmd :
At line:1 char:1
+ invoke-sqlcmd -Query "Select top 5 * from vwOffer" -ConnectionStrin ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Sqlcmd], ParserException
+ FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptComman
If I try and install adalsql.dll directly, I get a message stating that A higher version already exists and I can see the both versions of the dll can be found here:
C:\Windows\SysWOW64\adalsql.dll
C:\Windows\System32\adalsql.dll
and yet, invoke-sqlcmd cant find it. Any idea how to either (A) register the existing dll so invoke-sqlcmd can find it or (B) uninstall it so that it can be re-installed?
Incidentally, I am able to use Active Directory Authenticatoin with the 32-bit SQLCMD.exe, so I know the 32 bit dll is working fine. It's just the 64 bit dll that isn't loading properly...
So, this problem vexed me as well. I'm unclear as to how it happened, but maybe it's just coincidence that it happened when I installed the latest version of SSMS. My fix was to:
Navigate to Add or Remove Programs
In the little search window type sql, or just go find: "Active Directory Authentication Library for SQL Server".
Note: This will not be in Windows' installed programs list if you have installed Visual Studio 2019. You can run the same installer by invoking MsiExec.exe /I{6BF11ECE-3CE8-4FBA-991A-1F55AA6BE5BF} from a command prompt.
Uninstall that little guy
Navigate here and download the latest ADAL library (pick x64):
https://www.microsoft.com/en-us/download/confirmation.aspx?id=48742
Just for kicks, reboot
Your stuff should now properly load adalsql.dll!
Update #3, 2020-07-13: Installing the older version works, but is vulnerable to being clobbered by the SSMS and VS2019 installers. The reason the new version of ADAL doesn't work is because its installer fails to add a registry entry pointing to the 64-bit version of adal.dll. I added an answer below which includes the missing registry value, which you can add yourself. Once that's done, you should never need to do this dance again. - #Tullo_x86
The bewilderingly simple solution to this annoying problem
Ensure you actually have ADAL installed (the existence of C:\Windows\system32\adal.dll is plenty)
Paste this into a .reg file:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSADALSQL]
"TargetDir"="C:\\Windows\\System32\\adal.dll"
Double-click the .reg file to install that value
You're done. Go celebrate!
Explain WTF is going on. Why this is necessary?
This error happens because the .NET adapter for SQL Server can't find adal.dll. But why is this? It's installed, right?
Well, the installer for the latest version of ADAL (packaged with VS 2019 and the latest version of SQL Server Management Studio) adds a registry entry for the 32-bit version of the DLL (at C:\Windows\SysWOW64\adal.dll), but does not add the entry for the 64-bit version (which gets installed to C:\Windows\system32\adal.dll). If you build and run your application in 32-bit mode, you'll never see this bug manifest.
This is simply a bug in the ADAL installer. Presumably it wasn't detected by Microsoft because both Visual Studio and SSMS are 32-bit applications and thus don't go looking for the 64-bit version.
In my case culprit was VS 2019.
It has newer version of ADALSQL package. For me it was at path "C:\ProgramData\Microsoft\VisualStudio\Packages\sql_adalsql,version=16.0.61903.25110,chip=x64,language=en-US", which I uninstalled and installed desired version to resolve the issue.
Hope this helps!
In my case, add/remove programs didn't show any installed instances of "Active Directory Authentication Library". Yet, trying to install the library would fail saying a newer version was installed.
I un-wedged myself by opening the registry editor (regedt32) and using the Find feature from
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer
looking for adalsql.
That got a hit with containing keys
DisplayName: Active Directory Authentication Library for SQL Server
DisplayVersion: 15.0.1300.359
along with, importantly, a path to the associated installer. For me it was something like c:\windows\installer\4c334521.msi. I ran that msi and was finally able to "uninstall". After that, running the installer from the 'library' link above finally worked.
Or you if planned to upgrade SSMS in the time being, simply uninstall "Active Directory Authentication Library for SQL Server", and repair SSMS.
Next time you upgrade SSMS it won't broke anything. SSMS bring his own adalsql.dll, and know how to upgrade it when you upgrade SSMS. But if you had installed adalsql with something else (or using https://www.microsoft.com/en-us/download/confirmation.aspx?id=48742 ), SSMS is somehow broken.