Link to home
Start Free TrialLog in
Avatar of brettr
brettr

asked on

How to run scripts with SQLCMD?

In MSSQL 2005, I'd like to update sprocs on the production server with sql files I have on the developer machine.  In SQLCMD, I'm trying to connect with the remote server but get the following error:

E:\Dev\Database\>sqlcmd -u myusername -p mypassword  sql111.abc.com
Sqlcmd: 'myusername': Unexpected argument. Enter '-?' for help.

What should this syntax look like?


Once that gets going, what does the syntax for running a script look like?  Is this correct?

-i c:\Dev\Database\sproc1_update.sql -o c:\Dev\Database\sproc1_update.Log.txt

Once I connect, can I than just run lines like the one above or do I need to put a connect statement with each line?

Is there a more secure way to connect than sending the user name and password through plain text?  All I need is some way to run the developer scripts on production to synch the two.

Thanks.
Avatar of appari
appari
Flag of India image

the switches are case sensitive
use -U and -P instead of -u and -p
>>Once that gets going, what does the syntax for running a script look like?  Is this correct?
>>-i c:\Dev\Database\sproc1_update.sql -o c:\Dev\Database\sproc1_update.Log.txt
yes that is correct any out put generated by your script goes to out file specified.
Avatar of brettr
brettr

ASKER

"the switches are case sensitive
use -U and -P instead of -u and -p"

Thanks.  Now I get the same error but on the server part:

E:\Dev\Database\>sqlcmd -U myusername -P mypassword  sql111.abc.com
Sqlcmd: 'sql111.abc.com': Unexpected argument. Enter '-?' for help.

It's usually in the format server\instance.  I'm only specifying the server.  Will that work?  

If the instance is included, would it look like
sql111.abc.com\myinstance
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brettr

ASKER

The documentation for sqlcmd is aweful.  There's basically zero examples.

After adding -s, I get this:

c:\Dev\Database>sqlcmd -U myusername -P mypassword -s sql111.abc.com
Msg 18452, Level 14, State 1, Server LocalServer, Line 1
Login failed for user 'myusername'. The user is not associated with a trusted SQL
Server connection.

It list my local server instance, "LocalServer".  Is it trying to connect with the local box instead of the server I've specified?