SSIS Package and Bat file - sql-server

How can I run a Stored Package with a .bat file? I am running it locally on a server.

To run a package from the command line, use the DTExec tool. The location of DTExec depends on the version of SQL you have installed. Assuming you have SQL Server 2008 R2, you could save the following text to a file with a .bat extension somewhere on your SQL server.
"C:\Program Files\Microsoft SQL Server\110\DTS\Binn\DTExec.exe" /f "D:\PathTo\MyPackage.dtsx"
Double click the the .bat file to execute the command above.
Here is more information on DTExec and BAT files.

Related

dtutil import ssis package from remote

I am trying to import an ssis package (.dtsx) from one server to another remotely but I face a strange issue. (dtsx is on Server-02 and need to be imported on Server-01)
Let me explain with 3 commands :
Running on Server-01
osql -E -h -Q "select name from [msdb].[dbo].[sysssispackages] where name like '%MIC%'"
This returns nothing, my package is not imported yet, that's ok.
I have a .bat file on Server-01 which contains the following command :
"C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET
DTSX is located in D:\ on Server-02, .bat file is located in D:\ on Server-01.
This bat file must be run in order to import the ssis package.
Then running on Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
It returns successful state. But then when I run again on Server-01 my osql command, it still returns 0 result. It seems the package hasn't been imported...
We could think that the bat file isn't working but if I run the bat file directly by double clic on Server-01, it also runs successfuly. Then I do the osql select, it returns 1 result, the package has been imported successfuly.
At this moment, I thought that the bat script was simply not executed remotely. So I changed it a little.
echo "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /FILE \\Server-02\D$\BAM_DM_IBZMICVU001.DTSX /COPY SQL;BAM_DM_IBZMICVU001 /QUIET > D:\debug.txt
Then from Server-02
WMIC /NODE:"Server-01" process call create "cmd.exe /A /C D:\\BAM_DM_IBZMICVU001.bat"
D:\debug.txt has been successfuly created on Server-01 which means the bat script also executed well...
Any idea of what could happen in my case ?

SSDT generate and publish database changes

I am currently using the following command to generate a database script using SSDT:
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Script /sf:DB.dacpac /Profile:publish.xml /op:Script.sql
and the following command to publish:
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish /sf:DB.dacpac /Profile:publish.xml
Is there anyway we can merge them so it can generate a script (for audit purpose) as well as publish on the database?
Yes, it is quite recent but when you publish you can also use "/DeployScriptPath:" and give it a path and it will save the script.
Older versions of SSDT you had to do exactly what you are doing but we can now use this to do it in one step.
This will have the latest sqlpackage.exe in case you need it:
https://www.nuget.org/packages/Microsoft.Data.Tools.Msbuild/
ed

SQL Server Config manager error: Cannot connect to WMI provider

I cant open my SQL server configuration manager getting this error message:
Cannot connect to WMI provider. You do not have permission or the server is unreachable. Note that you can only manage SQL Server 2005 and later servers with SQL Server Configuration Manager.
Invalid
I have searched online material and ran the mofcomp command as recommended: mofcomp “C:\Program Files (x86)\Microsoft SQL Server\120\Shared\sqlmgmproviderxpsp2up.mof”
I am now getting this error message:
MOF file has been successfully parsed
Storing data in the repository…
An error occurred while processing item 10 defined on lines 73 – 79 in file C:\Program Files (x86)\Microsoft SQL Server\120\Shared\sqlmgmproviderxpsp2up.mof:
Compiler returned error 0x80070005Error Number: 0x80070005, Facility: Win32
Description: Access is denied.
Can you please help me out, been 2 weeks sited with this problem
Run Cmd as Administrator and execute these commands:
First go to SQL Shared folder according to your sql version:
SQL 2008: C:\Program Files (x86)\Microsoft SQL Server\100\Shared\
SQL 2012: C:\Program Files (x86)\Microsoft SQL Server\110\Shared\
SQL 2014: C:\Program Files (x86)\Microsoft SQL Server\120\Shared\
SQL 2017: C:\Program Files (x86)\Microsoft SQL Server\140\Shared\ -------> My version is 2017
SQL 2019: C:\Program Files (x86)\Microsoft SQL Server\150\Shared\
Find more versions here
cd "C:\Program Files (x86)\Microsoft SQL Server\140\Shared"
Then:
mofcomp sqlmgmproviderxpsp2up.mof
Update:
The problem occurs because the Windows Management Instrumentation (WMI) provider configuration file for manage SQL Server services is missing. So the mofcomp command repairs or recreates it.
Here is more explanation:
https://learn.microsoft.com/en-us/windows/desktop/wmisdk/mofcomp
Run the #Fereydoon Barkzehy codes with Administrative Access
Sample -
cd C:\Program Files (x86)\Microsoft SQL Server\110\Shared
cd C:\Program Files (x86)\Microsoft SQL Server\140\Shared
mofcomp sqlmgmproviderxpsp2up.mof
depends on where the file "sqlmgmproviderxpsp2up.mof" is present
Youtube video
The best solution for me was to uninstall the instance and reinstall a fresh instance. This worked 100%.
What worked for me was to download the SQLEXPR_x64_Enu, run the Setup.exe and use the Repair option.
I have the same issue but it is not working at first. Second I already restarted my PC but it is not working either. What I found out is that you will run this on the folder where your SQL Server Management Studio is installed and not on the MS SQL Instance folder.
My SQL Server Management Studio which is 2016 is installed in
C:\Program Files (x86)\Microsoft SQL Server\130
But I keep on running changing folder on which I installed on my SQL Server 2012 instance:
C:\Program Files (x86)\Microsoft SQL Server\110\Shared\
After that, just run the command: mofcomp sqlmgmproviderxpsp2up.mof as everyone suggest in here.
So keep it mind the folder since that may affect your troubleshooting.
By trial and error I finally found this working solution:
I searched all sqlmgmproviderxpsp2up.mof files under C:\Program Files (x86)\Microsoft SQL Server
Running CMD as administrator I did for each result found above:
i) Change directory to go to the directory
ii) Run mofcomp sqlmgmproviderxpsp2up.mof
Reboot
Then, it works.
doing a fresh OS installation also worked for me as well. but this is a pain. Sometimes you can run the:
“C:\Program Files (x86)\Microsoft SQL Server\120\Shared\sqlmgmproviderxpsp2up.mof”
Sometimes it helps and sometimes it doesn't, all you need to do is do a fresh OS installation and then SQL installation.

unable to run sharepoint powershell script from sql server agent job

I have a powershell script which is working fine from PowerShell ISE, the script will move the local files to SharePoint 365 documents. When I schedule a SQL server agent job using this script getting the error below.
Please advice me what I need to do to run this script.
abc\SQLServiceAcc. A job step received an error at line 10 in a
PowerShell script. The corresponding line is 'Add-Type -Path
"C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"'. Correct the
script and reschedule the job. The error information returned by
PowerShell is: 'Could not load file or assembly 'file:///C:\Program
Files\Common Files\Microsoft Shared\Web Server
Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll' or one of its
dependencies. This assembly is built by a runtime newer than the
currently loaded runtime and cannot be loaded. '. Process Exit Code
-1. The step failed.
It depends how you are running the script and which version of SQL Server you are using.
Look at http://www.travisgan.com/2013/05/sql-server-agent-job-and-powershell.html

Windows batch file to copy multiple SSIS packages to SQL Server using DTUTIL command

I am trying to copy multiple ssis packages to SQL server using a windows batch file.
I have the below dtutil command which works fine.
for %I in (*.dtsx) do dtutil /FILE "%I" /COPY SQL;"//%~nI" /DestServer SQLServer
what should i change in this command to make this to a bat file. Also i need a log file of the deployment.

Resources