I am using sqlcmd to query a SQL server database from a UBUNTU machine (an ODBC driver was installed for this purpose)
If I pass the following command:
sqlcmd -S xyz -d xyz -U xyz
I am prompted for a password, and I can then successfully query the database in question. But, if pass the command below, I get the message 'Login failed for user ****':
sqlcmd -S xyz -d xyz -U xyz -P xyz
I need to be able to send the password in one pass, as I need to pass an input query file and send the output to a specific location. Once I log into the database by waiting for a password prompt, I can no longer specify input/output files. Any insights would be much appreciated
Have you tried it without the space between the -P and the value? The docs show them glued together.
Related
we are migrating some shell scripts from unix to linux and we are bsolutely newby.
Some scripts invoke slq scripts which contain instructions for operations on a syabase database that we are migrating to sql server database, so we are rewriting these sql scripts as well.
Our new shell scripts call directly the sqlcmd command and already pass db server, db name, user and password stored in environment variables:
sqlcmd -S $SERVER_DB -d $NAME_DB -U $USER_DB -P $PASSW_DB < /home/scripts/update_data.sql
but at the first line of each sql script we need to convert, we are finding similar statement:
isql -U$DBUSER -P$DBPASSWD -w 80<< EOF|grep -v "return status" >>/usr/local/abc/ABC.txt
Perhaps because for some users a certain connection to the syabase database was set by default, so it was sufficient to put the call to the isql command on the first line of the sql file passing only the user and password, but in our case using sqlcmd we already pass everything directly in the shell script, it is not necessary to invoke the sqlcmd command again at the first line of the sql script.
So what should we write in place of isql call but leaving the part that redirects the output to the ABC.txt file?
Thanks in advance
I need to make a change in my local Sybase DB quite often,
changing "version2" value to "10.076" and sometimes to "10.080".
If instead of opening the Interactive SQL tool, typing in DB's credentials each time, I could just run a "76.bat" or "80.bat" file, it would be very handy.
The query is:
UPDATE "trogxxx"."xxversion" SET "version2"=10.076 WHERE "version"='2002'
And credentials:
UserID: Trogxxx
Password: Trogxxx2018
ServerName: dem8
How would a .BAT file look like, in order to log in and run the update?
You could create a basic bat file calling to isql on the command line and use the -i flag to indicate the SQL script containing the update statement which then gets called as an input file. You could prompt for the -U (username) and -P (password) options or hardcode as much as you want.
Syntax: isql -U username -P password -S server -i input_filename
This assumes your environment has sufficient settings for your normal Sybase client e.g. %SYBASE% etc.
I'm attempting to use bcp.exe to insert rows into an Azure database.
The command line I am using is:
bcp <database>.dbo.<table> IN <datafile> -n -S <server> -U <username> -P <password> -k -e <errorfile>
When executed against a local database, all is fine, the data is inserted.
When executed against the Azure database, bcp says all rows were sent to SQL Server, the error file is empty, the Azure resource usage shows a spike, but no data has made it into the database.
I have tried a data file with a single row.
I have tried -c and -w.
When executing a similar insert using SSMS, the data is inserted.
Any ideas?
Are you using the tcp syntax in your server name (i.e. tcp:servername.database.windows.net) and a user name convention of username#servername?
I followed this article with success: http://thecodegarden.net/bulk-insert-azure-sql/
Otherwise what you have looks good.
I am trying to run multiple SQLCMD statements (that archive tables in SQL Server 2008 and create restore scripts) from windows .bat file. My scripts work like first I perform SQL Authentication and then I input SQL scripts to output restore files
sqlcmd -S <Server name>\<instance> -U user
sqlcmd -i ArchiveTable1.sql -o RestoreTable1.sql
sqlcmd -i ArchiveTable2.sql -o RestoreTable2.sql
sqlcmd -i ArchiveTable3.sql -o RestoreTable3.sql
Problem is that after sqlcmd authentication, there appears prompt 1> and does not execute my next statements. On entering Quit, my next statements get executed but in output files I see authentication invalid error.
I dont want to have sql authentication with each sqlcmd statement.
If there is issue with my approach, can somebody guide me to use other design.
Three sqlcmd execution, three authentications:
sqlcmd -S <Server name>\<instance> -U user -i ArchiveTable1.sql -o RestoreTable1.sql
sqlcmd -S <Server name>\<instance> -U user -i ArchiveTable2.sql -o RestoreTable2.sql
sqlcmd -S <Server name>\<instance> -U user -i ArchiveTable3.sql -o RestoreTable3.sql
I dont want to have sql authentication with each sqlcmd statement
What you want matters little. You must do what is correct. If you have a justification for your unusual requirement, state the problem clearly, don't offer a solution and ask us to make it work.
If you want to avoid repeating user info and password in batches, and more importantly if you want to avoid leaving these passwords lying around in batches, use the sqlcmd environment variables SQLCMDUSER and SQLCMDPASSWORD:
The SQLCMDPASSWORD environment variable lets you set a default password for the current session. Therefore, passwords do not have to be hard-coded into batch files.
Simply set the SQLCMDUSER, SQLCMDPASSWORD (and maybe SQLCMDSERVER) and then invoke the batch. This way the batch does not need to contain any hard coded password.
I'm busy backing up my postgres db, I run the following command
pg_dump -d data -U postgres -h 127.0.0.1 -CdiOv > data.sql
I however have one problem I get asked for the password, if I want to add this into a cron I do not want to get promted for the password. Is there any way to do this without the password prompt?
First of all: never use -d option to pg_dump. Do you even know what it does?
Second: use pgpass file or PGPASSWORD env variable.
Use ~/.pgpass.
pgpass documentation
Lots more details to be found on Google, searching for "pg_dump password".