9

I'm developing a .Net-application that would deploy a dacpac on a client machine. For that purpose I would require SqlPackage.exe to deploy the dacpac. I need a absolute path of SqlPackage.exe to make my application work irrespective of client's machine configuration.

Can you please help me to achieve this.

Thanks, Yogesh

Yogesh Irmal
  • 111
  • 1
  • 1
  • 7
  • 2
    An alternative to `sqlpackage` is the [Microsoft.SqlServer.Dac package](https://www.nuget.org/packages/Microsoft.SqlServer.Dac/), which allows you to [programmatically deploy](https://msdn.microsoft.com/library/microsoft.sqlserver.dac.dacservices) DACPACs. – Jeroen Mostert May 17 '17 at 08:50
  • This is the option I guess I would require to consider. Thanks Jeroen – Yogesh Irmal May 17 '17 at 09:09
  • 1
    I realize that this question is a little old now, but just to point out that the suggested NuGet package doesn't look like it is (or ever really was) maintained. There are only two versions and the latest is over five years old. – jamesmus Oct 30 '19 at 14:51

3 Answers3

13

You can install sqlpackage.exe in two ways:

  • SSDT (SQL Server Data Tools): the location will be VS Install Directory\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\{SqlVersion}, VS install directory: C:\Program Files (x86)\Microsoft Visual Studio {VsVersion}.0
  • SQL Server Management Studio (SSMS) and the Dac Framework MSI: C:\Program Files (x86)\Microsoft SQL Server\{SqlVersion}\Dac\bin

SqlVersion is 140 for the SQL Server 2017, 130 for the SQL Server 2016 etc.

VsVersion is 14 for Visual Studio 2017

More details in this question.

Dávid Molnár
  • 10,673
  • 7
  • 30
  • 55
  • Thanks David. Actually we are executing sqlpackage.exe from batch file, so we need a exact location of sqlpackage.exe in client machine. Client may have installed it in C: or D: or any drive. We cant keep the path static. – Yogesh Irmal May 17 '17 at 08:32
  • 1
    Actually, I would just copy the `sqlpackage.exe` file and all of it's dependencies and deploy it with my batch file. So my clients do not have to install anything, I do not have to find the correct path and everyone is happy :) – Dávid Molnár May 17 '17 at 08:42
  • but I guess we are not allowed to redistribute Microsoft assemblies and ship as a part of our product to client. – Yogesh Irmal May 17 '17 at 09:00
  • Another option is to test out all possible paths. In the batch script do: if Exists (path), for c:\..., d:\.., e:\.. etc. Maybe not foolproof, but could work. – Dávid Molnár May 17 '17 at 09:14
  • Yes that would work out..Jeroen just suggested one more option an alternative to sqlpackage.exe. I will try this if not worked then only option I remained with test out all possible paths. – Yogesh Irmal May 17 '17 at 09:29
  • The Data-Tier Application Framework is redistributable. See the license terms for details, but the big picture is that you're allowed to ship it with your app and use it to perform database operations. – Steven Green May 17 '17 at 23:56
  • If this is the case then its great.. Thanks Steven for the help – Yogesh Irmal May 18 '17 at 08:46
  • I think 140 is for SQL Server 2017. 2016 corresponds to 130. – nawfal Dec 02 '17 at 16:39
  • 2
    This does not work. I have installed SSDT with all the options enabled and the Extensions folder is not there. *edit:* The VS2017 install directory has changed, which is not documented anywhere that I can find - it is now at `C:\Program Files (x86)\Microsoft Visual Studio\2017` – Tom W Dec 07 '17 at 13:28
  • 1
    Use vswhere.exe to help find Visual Studio instances. This could help you find `sqlpackage.exe`. `https://github.com/Microsoft/vswhere` – DaleyKD Dec 27 '17 at 19:05
  • Note - with the latest 64bit version of VS it's no longer 'Program Files (x86)' for the VS installation it's just 'Program Files' – Tom John Sep 29 '22 at 09:47
3

To find sqlpackage programmatically you can make use of the TaskModuleSqlUtility powershell library. Either run the Invoke-DacpacDeployment from the powershell script (sorry not C#) or make use of Get-SqlPackageOnTargetMachine function for sqlpackage.exe path.

Search for tests in github for samples.

nawfal
  • 70,104
  • 56
  • 326
  • 368
1

you also can download from microsoft doc site

https://learn.microsoft.com/en-us/sql/tools/sqlpackage-download?view=sql-server-ver15&viewFallbackFrom=sql-server-ver17

and check your version of sql and get correct instructions

Turbot
  • 5,095
  • 1
  • 22
  • 30