| Author |
Topic |
|
etnad7
Starting Member
16 Posts |
Posted - 2010-09-16 : 02:38:12
|
| hi guys, just want to ask how can i use OSQL on batch file (dos cmd), where in i wan to run sample.sql (inside the sql itself not on directory of the pc)? thanks! |
|
|
etnad7
Starting Member
16 Posts |
Posted - 2010-09-16 : 04:29:44
|
| 1> EXEC 'Test-Select'2> goMsg 170, Level 15, State 1, Server *******, Procedure , Line 1[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near'Test-Select'.1>test-select is the name of the job, what could be wrong? thanks! |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-16 : 04:52:08
|
you have to tell OSQL which server to run the code on and which database to run the command on and which user to log in as and what password to log in as.try doing OSQL /? on the command line -- you'll get some help.The first thing to do is check that you can connect to something. For example to connect to may local instance of SQLSERVER and the database ReFlex_Main and then select the top 1 everything from the person table I'd do thisOSQL -Usa -Pmuppet -S127.0.0.1 -dReFlex_Main -Q"SELECT TOP 1 * FROM PERSON" Hope that helps.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-16 : 04:57:26
|
to run a stored proc:osql -Usa -Pmuppet -S127.0.0.1 -dReFlex_Main -Q"EXEC sp_who" Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
etnad7
Starting Member
16 Posts |
Posted - 2010-09-16 : 05:01:07
|
| i tried this:C:\>osql -U user1 -P pass -d AADATA -S RDSERVER /q test-select -o C:\dante2.txtexitresult is:[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax nearthe keyword 'select'.1> pls. help guys..TIA! take note job name is Test-Select. |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-16 : 05:10:29
|
| What do you mean by job Name?Is this a stored proc? or is it a sql server agent job.Also -- the - is causing a problem. A better name would be testSelectCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
etnad7
Starting Member
16 Posts |
Posted - 2010-09-16 : 06:06:20
|
| sql script name is test-select, i think it's a stored procedure since the script is inside the sql. thanks! |
 |
|
|
etnad7
Starting Member
16 Posts |
Posted - 2010-09-16 : 06:07:54
|
| i'm running in on the server itself. |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-16 : 06:29:18
|
quote: sql script name is test-select, i think it's a stored procedure since the script is inside the sql. thanks!
OK -- how would you execute the script from management studio?if it's a stored proc then the sql would be something likeEXEC dbo.<stored proc name> <paramaters> Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
etnad7
Starting Member
16 Posts |
Posted - 2010-09-16 : 06:42:48
|
| hi charlie, got it now! i was just calling the wrong name, what i was calling is the job name not the script itself, when i tried to call the script itself, it works! thanks for your help. My next question is how can i do error handling? |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-16 : 06:49:53
|
quote: My next question is how can i do error handling?
LOL!Might be a good idea to start a new thread. Explain what kind of errors you are getting and go from there.Glad I could help.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
etnad7
Starting Member
16 Posts |
Posted - 2010-09-16 : 07:00:40
|
| ok thank you so much charlie! |
 |
|
|
|