Create roll-on script using Database Project that does not require SqlCmd - database-project

When using database projects, compare, and then Generate Script then the generated scripts is default for SqlCmd. E.g. it generates a row like:
/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF;
*/
:setvar __IsSqlCmdEnabled "True"
Is it possible to generate scripts in the Database Project that just generates the stuff that can be executed via SQL Server Management Studio?
(I use Visual Studio 2022)

Related

xp_cmdshell throwing 'null' but working in command prompt

I am using xp_cmdshell command to process csv file to a folder. My query is as below:
Exec master..xp_cmdshell 'C:\test\mydotnetapp.exe -s:03/09/2020 -t:1 -l:1,2,3,4,7 -d C:\test'
In SSMS this command returns null. But in command prompt when I do:
cd C:\test
mydotnetapp.exe -s:03/09/2020 -t:1 -l:1,2,3,4,7 -d C:\test
The same query is working perfectly fine. A couple of things:
xp_cmdshell is enabled
SQL Server has access to the folder
Only this xp_cmdshell command is not working. my other xp_cmdshell is working fine
Any help on how this can be fixed?
If this is run as part of a SQL Job regularly scheduled, run it as a task outside of SQL Server.
Many production DBAs won't let any process run XP_CMDSHELL given the security issues.
If the CSV is well-formed, it can be mapped into SQL Server as a table (not recommended).
It can be imported directly into SQL Server.
Lastly, many production DBAs won't install any custom process code on a production SQL Server machine. The SQL Server machine is dedicated to running only SQL Server plus the minimum extra needed for security and monitoring.

Windows Server Permissions: What permission changes are needed to run 'sqlcmd' through IUSR?

A little background: I need to invoke sqlcmd to remotely run .sql files via PHP. I am trying to use this function call: exec("sqlcmd -?", $second); There is zero output after running this command. Running this command under my current user works fine.
PHP runs under IUSR according to PHP's get_current_user(); function so it would be logical to change the permissions on sqlcmd to allow PHP to run sqlcmd (I give full permissions temporarily just for testing):
Then I retest the PHP script and again no output. I decide to restart IIS. Still no output.
What permissions are needed to run sqlcmd under IUSR?

How to take SQL Server 2012 schema + data dump using command prompt

I have a database in SQL Server 2012. Now I am looking for some windows commands that will generate an .sql file for the schema[create statement] and another .sql file for the data[insert statement] of that database. I need to do this using command prompt. So I can't use the Generate Scripts option provided in SQL Server Management Studio.
Thanks in advance
The schema dump from command-line can be done using SQLPackage.exe. The command is -
"C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe" /action:Extract /tf:<drive:\folder_name\file_name.dacpac> /SourceConnectionString:"Data Source=<server_name>;Initial Catalog=<db_name>;Integrated Security=SSPI;Persist Security Info=False; /su:<user_name> /sp=<password>
If using windows authentication then input username = password = space. The file paths that contain spaces must be enclosed in quotation marks.
See https://www.katieandemil.com/sqlpackage-exe-extract-dacpac-command-line?tab=article for more details.

How can I execute SQL scripts using TeamCity?

I´m new with TeamCity and I don´t know how to run SQL scripts with it.
Is the way simply selecting the path of those scripts in a Command Line Build Runner ?
I´m pretty lost.
Regards.
In a command line build step:
Command executable: c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe
Command parameters: -S <server> -i <path_to_file> <== Note: that's a capital -S!
You may need to change the 100 to something else, depending on the version of the SQL Server tools that you have installed on the build agent.
I believe that SQLCMD / SQLPLUS / MYSQL are available as standalone executables which you can install on the TeamCity server.
Microsoft® SQL Server® 2008 R2 Feature Pack
Oracle SQL Plus
MYSQL Command Line
However, without knowing your actual SQL Platform this may differ and the provider should have an alternative.
You can then create a Command Line Runner to call the executeable and pass in the parameters required, which are further explained here.
Using the sqlcmd Utility
Using sqlplus utility
If you are looking at doing Database Migrations as part of your CI process, it would also be worth checking out RoundhousE

Execute stored procedure from cmd.exe?

Is there anyway to run a stored proc from cmd.exe ?
p.s.
I know how to create exec file c# and to run it.
I'm asking without any code :
Just me and cmd.exe.
edit
me and cmd.exe : meaning I don't want to write any code. Internal SQL Server help exe files of sql is fine !
sorry for not clarifying this !
Try using the SQLCMD Utility :
An example:
sqlcmd -E -S server_name -d database_name -Q "EXEC schema.storedprocedure parameter01, parameter02"
If you'd like to explore other options I'd like to share this link:
Command Prompt Utilities: Applicable for SQL Server 2005
For sql server 2005+ use its SQLCMD utility, as #Nonim answered
for versions prior to 2005 use its OSQL utility, its usage is similar to SQLCMD
Wrap it into the .cmd file and you're in! No needs to write something, just click'n'go! 8-)
C# files are not executable. But the compiled program from them is.
CMD is not C# parser neither SQL client. From the CMD you call a program that serves a file. You and CMD can navigate to drive A: to execute file there, to delete files and so on.
CMD is emulated environment of DOS, which is also OS - you need a program to execute the SQL queries. See this (Sqlcmd program of SQL Server):
http://msdn.microsoft.com/en-us/library/ms165702.aspx