SQL Server enters single user mode after cmd installation - sql

I am installing SQL Server Express 2017 using the command line. Once the install is done I use a batch file to create a database. The database creation fails giving a message that : login with 'sa' failed, The server is in single user mode
I have used the installation syntax given on the msdn website and my DB creation script is a batch file which creates a DB after confirming that SQL 2017 is installed. I am logging the errors in a file which gives me the single mode error information. Below is the installation statement I am using through cmd
SETUP.exe /q /ACTION=Install /BROWSERSVCSTARTUPTYPE=Automatic /SQLSVCSTARTUPTYPE=Automatic /FEATURES=SQL /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /AGTSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSVCINSTANTFILEINIT="True" /IACCEPTSQLSERVERLICENSETERMS /SAPWD=<Password> /SECURITYMODE=SQL
The code to install the DB is :
%OSQLEXE% -S %SERVER% -U %USERNAME% -P %PASSWORD% -i "%AgentPath%\CreateDatabase.sql" >> c:\InstallLog.txt
Ideally my DB should be created but for some reason I get this error. Can someone please help?

Related

Running multiple SQL files in Microsoft SQL Server

I have some SQL files which I can run in a single script in oracle like this:
start create_tst_prod_class_tbl.sql
start create_tst_tran_ins_type_tbl.sql
start create_tst_order_type_tbl.sql
start create_tst_timezone_tbl.sql
Now I want to do that in MSSQL too but I could not figure out how. I have tried following things:
Writing a query like this:
:r "C:\Users\Ferid\Desktop\standard\create_tst_prod_class_tbl.sql"
:r "C:\Users\Ferid\Desktop\standard\create_tst_tran_ins_type_tbl.sql"
:r "C:\Users\Ferid\Desktop\standard\create_tst_order_type_tbl.sql"
:r "C:\Users\Ferid\Desktop\standard\create_tst_timezone_tbl.sql"
and activate SQLCMD mode but when I execute it this error occurs:
A fatal scripting error occurred.
Incorrect syntax was encountered while parsing EXIT.
Creating a batch file in the folder where the SQL files are with this content:
SET SQLCMD=sqlcmd -S<Servername> -d<databasename> -U<Username> -P<Password> -E
for %%d in (*.sql) do %SQLCMD% -i%%d
When I run it following error occurs:
Sqlcmd: The -E and the -U/-P options are mutually exclusive.
Creating a batch file in the folder where the SQL files are with this content:
for %%G in (*.sql) do sqlcmd /S <servername> /d <databasename>
-U <username> -P <password> -i"%%G"
pause
When I run it following error occurs:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Named Pipes Provider:
Could not open a connection to SQL Server [53]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related
or instance-specific error has occurred while establishing a connection to SQL Server.
Server is not found or not accessible. Check if instance name is correct and if
SQL Server is configured to allow remote connections.
For more information see SQL Server Books Online..
Sadly I have no access to remote connections options.
Are there any other options or ways to fix these errors?
Your case 2. is working:
SET SQLCMD=sqlcmd -S<Servername> -d<databasename> -E
for %%d in (*.sql) do %SQLCMD% -i%%d
OR
SET SQLCMD=sqlcmd -S<Servername> -d<databasename> -U<Username> -P<Password>
for %%d in (*.sql) do %SQLCMD% -i%%d

Getting error in SQL Server executing get-wmiobject

I am trying to execute following PowerShell query in SQL Server
xp_cmdshell "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"
After executing this, I am getting error:
'get-WmiObject' is not recognized as an internal or external command,
operable program or batch file.
I want to execute this command in all SQL Servers. It's getting executed on SQL Server 2008, but on SQL Server 2012, it's throwing that error due to version or some PowerShell component is not installed.
Can you to please look at the code and let me know
Try:
xp_cmdshell 'PowerShell.exe -noprofile -command "get-WmiObject Win32_LogicalDisk -AV-RISCVMSQL114 | Format-Table -Property DeviceID,FreeSpace,Size"'
If this doesn't work logon to the server open PowerShell with administrator rights. Type Get-ExecutionPolicy and check that Execution Policy is set to Unrestricted. If it isn't then enter the following, then type 'A' (Yes to All):
Set-ExecutionPolicy Unrestricted
If this still doesn't work try upgrading to at least PowerShell V3. But if this is not possible you can try repair your corrupt PowerShell V2 WMI repository with:
winmgmt /verifyrepository
If repository is found to be inconsistent run Winmgmt /salvagerepository and Winmgmt /resetrepository and verify after each. If it is still inconsistent try the following steps:
Go to Task Manager>> Services >> Open Service >> Windows Management Instrumentation service, and change the start up type to Manual.
Stop the WMI service:
net stop winmgmt
Rename the repository folder (C:\Windows\System32\wbem\Repository) to some else 'Repository_OLD'.
Start the WMI service:
net start winmgmt
Set the service back to auto start.
Failing Re-register all of the dlls and recompile the .mofs in the Wbem directory with the following .bat script and then reboot.
#echo off
sc config winmgmt start= disabled
net stop winmgmt /y
%systemdrive%
cd %windir%\system32\wbem
for /f %%s in (‘dir /b *.dll’) do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /regserver
sc config winmgmt start= auto
net start winmgmt
for /f %%s in (‘dir /s /b *.mof *.mfl’) do mofcomp %%s

Chef-client does not work from Workstation but does work directly on the server

I have a chef recipe that runs a chocolatey install for Microsoft SQL server. From my workbench when I run
knife winrm [IP] 'chef-client -o "recipe[NetDevMachine::default]"' -m -x 'domain\myuser'
over a node it fails with the error:
532459699 or sometimes 2022834173 or 2057043966
However if I log onto the VM as the same user and locally run
chef-client -o "recipe[NetDevMachine::default]"
It works. Does anyone know what the difference is between running chef-client locally and running it remotely from the workbench? What does chef-client do differently here? Both are pulling the recipe from the same chef-server repo.
Additional Details
I am using the same user for both
I have successfully run other recipes from the workstation, it's just this MicrosoftSQLServer install that's not working
running "knife winrm [IP] 'choco install MicrosoftSQLServer' -m -x 'domain\myuser' also does not work
Recipe contents:
powershell_script "choco install MicrosoftSQLServer2014" do
code <<-EOH
choco install MicrosoftSQLServer2014
EOH
end
Error:
[ERROR] Running C:\Users\myuser\AppData\Local\Temp\MicrosoftSQLServer2014\setup.exe with
/QUIET /IACCEPTSQLSERVERLICENSETERMS /ACTION=INSTALL /INSTANCENAME=MSSQLSERVER /FEATURES=SQL,TOOLS,LOCALDB
/SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS=BUILTIN\ADMINISTRATORS
/SKIPRULES=REBOOTREQUIREDCHECK UIMODE=AUTOADVANCE was not successful.
Exit code was '-532459699'.
Edit - the only difference I can see is that one runs in the foreground and the other doesn't. So the location of the compile chef-script is /temp/2 for the failing run. I don't know if there is a way to force chef to run in the foreground or if that will even help.
Thanks
I never got to the bottom of this and still don't understand how running the chef client remotely using knife was different from running chef client directly on the VM. Perhaps it was something to do with the handling of credentials or permissions when remotely sending commands.
But I did find that removing chocolatey and replacing it a command line silent install inside a chef powershell resource allowed me to install MSSQL.

Running commands on Remote machine using PsExec from Msbuild invoked via Jenkins

I am using psexec(with MSbuild Script) to run an xCopy on a server from Jenkins(Hudson). The command runs ok when run through Command Prompt(as System user), but gives the following error when tried using Jenkins. This is the command I am using from Msbuild script:
psexec \\<RemoteMachine> /accepteula -i -u <Domian\User> -p <Pass> -s cmd /c xcopy <Path1> <Path2> /e /i
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Connecting to ..
Couldn't access :
Connecting to ...
**error MSB3073: The command "psexec \\<RemoteMachine> /accepteula -i -u <Domian\User> -p <Pass> -s cmd /c xcopy <Path1> <Path2> /e /i " exited with code 6.**
I have tried too many options but no luck so far.
Does anyone tried the same using Jenkins? Help will be really appreciated.
Are there any other ways to achieve this using some other tools without any problem. Please share.
Just wanted to post the solution here, as I figured it after some time.
The Remote Machine should have this user added in the Administrators Group.
This will resolve the connection issue. :)

Installing Visual Studio Test Controller on Azure instance is not working

I already mentioned the problem in another thread, but I thought the root of the error was another. Now I know the real error, but cannot solve it, and don't understand it.
I want to install Visual Studio Test Controller on an Azure instance. I am trying to do that via a startup task, that runs a batch-file which in turn downloads the test controller installation file and installs it on the instance.
The problem is: that does not work when running the installation via startup task. When I log in to the machine via RDP and double click the exact same batch file everything works fine.
Here are some additional information:
This is my batch file I execute:
powershell $command = "set-executionpolicy Unrestricted"
powershell $command = ".\setupController.ps1" -NonInteractive >; out.txt
echo Setup TestController >> %~dp0out.txt
cd E:\approot
timeout /T 60
"E:\approot\testcontroller.exe" /full /q /Log %~dp0install.log
echo Setup has been executed! >> %~dp0out.txt
net user vstestagent MyPassword! /add
net localgroup Administrators vstestagent /add
REM Create a task that will run with full network privileges.
net start Schedule
schtasks /CREATE /TN "Configure Test Controller Service" /SC ONCE /SD 01/01/2020 /ST 00:00:00 /RL HIGHEST /RU vstestagent /RP MyPassword! /TR e:\approot\configcontroller.cmd /F
schtasks /RUN /TN "Configure Test Controller Service"
This is the startup task of the role:
<Task executionContext="elevated" taskType="background" commandLine="setupController.cmd"></Task>
The batch file, as well as the installation file of Test Controller are located in E:\approot folder
The installation logfile of testcontroller says something like that:
0A88:0ABC][2013-04-12T10:36:04]: Creating a system restore point.
[0A88:0ABC][2013-04-12T10:36:04]: System restore disabled, system restore point not created.
[0A88:0ABC][2013-04-12T10:36:04]: Caching bundle from: 'C:\Resources\temp\48c0ec5daf5846cab7f53f6b5c80dc6f.TestController\RoleTemp\{44f19fb6-98e0-4462-886c-c5e56d82dfd3}\.be\vstf_testcontroller.exe' to: 'D:\ProgramData\Package Cache\{44f19fb6-98e0-4462-886c-c5e56d82dfd3}\vstf_testcontroller.exe'
[0A88:0ABC][2013-04-12T10:36:04]: Registering bundle dependency provider: {44f19fb6-98e0-4462-886c-c5e56d82dfd3}, version:
11.0.51106.1
[0A40:09EC][2013-04-12T10:36:04]: MUX: Cache Begin
[0A40:064C][2013-04-12T10:36:05]: Error 0x80070070: Failed to set end of file.
[0A40:064C][2013-04-12T10:36:05]: Error 0x80070070: Failed to extract all files from container.
[0A40:09EC][2013-04-12T10:36:05]: Error 0x80070070: Faild to begin and wait for operation.
[0A40:09EC][2013-04-12T10:36:05]: Error 0x80070070: Failed to extract payload: a25 from container: WixAttachedContainer
[0A40:09EC][2013-04-12T10:36:05]: Failed to extract payloads from container: WixAttachedContainer to working path: E:\approot\testcontroller.exe, error: 0x80070070.
[0A40:0B98][2013-04-12T10:36:05]: Error 0x80070070: Failed while caching, aborting execution.
[0A88:0ABC][2013-04-12T10:36:05]: Removed bundle dependency provider: {44f19fb6-98e0-4462-886c-c5e56d82dfd3}
... Some Rollback and cleanup
[0A40:0B98][2013-04-12T10:36:06]: Variable: WixBundleTag = vstf_testcontroller,1031
[0A40:0B98][2013-04-12T10:36:06]: Variable: WixBundleVersion = 11.0.51106.1
[0A40:0B98][2013-04-12T10:36:06]: Exit code: 0x643, restarting: No
I really don't know where the problem is - especially because when I run the batch file via RDP everything works just fine.
The only difference seems to be the user esecuting the batch: Startup Tasks run with administrative priviledges and I think my RDP account is another, but also has administrative priviledges....
Best regards
Sebastian
I still don't know WHY it is that way, but the installation works, if you do it via a scheduled task.
Because I thought the only difference is maybe the account installing the software, I first tried to install the test controller via runas command, but I could not pass a password along with the command. So I created a scheduled task for installing the test controller and was able to pass user credentials along with the command. Now my setupController.cmd looks like this:
powershell $command = "set-executionpolicy Unrestricted"
powershell $command = ".\setupController.ps1" -NonInteractive >; out.txt
echo Setup TestController >> %~dp0out.txt
cd E:\approot
echo Setup has been executed! >> %~dp0out.txt
net user vstestagent MyPassword! /add
net localgroup Administrators vstestagent /add
REM Create a task that will run with full network privileges.
net start Schedule
schtasks /CREATE /TN "Install Test Controller Service" /SC ONCE /SD 01/01/2020 /ST 00:00:00 /RL HIGHEST /RU vstestagent /RP MyPassword! /TR "E:\approot\testcontroller.exe /full /q /Log %~dp0install.log" /F
schtasks /RUN /TN "Install Test Controller Service"
timeout /T 120
schtasks /CREATE /TN "Configure Test Controller Service" /SC ONCE /SD 01/01/2020 /ST 00:00:00 /RL HIGHEST /RU vstestagent /RP MyPassword! /TR e:\approot\configcontroller.cmd /F
schtasks /RUN /TN "Configure Test Controller Service"
Hope it helps somebody else also.