Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
leite333
Starting Member
8 Posts |
Posted - 2011-08-01 : 09:47:55
|
| HiI wanna some really help with something i tried to do but i cant.I have a software program and i want to run a sql query external.So i create 2 files The first one is a bat file wich i wrote on it:CD:SQLCMD -S PC\SQLEXPRESS -U sa -P admin -i <C:\sqlquery.sql>And the second is a txt file saved as sql with a simple queryAs much i tried i cant do it work external. For example just run the bat file and execute the sql file....When i open command prompt i can make it work...But i dont wont that... I dont know if i have serius syntax problems...Can anyone help????? Can i do it only with bat file???? I have Windows 7 64bit i dont know if this is a problem Any other ideas will be helpful(otherways) |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-08-01 : 21:14:38
|
What is the error message you are getting?Not sure what the CD: is for? Is it a label?Also, if you are putting the filename within angle brackets, don't.Also, if not already in the sqlquery.sql you should have code to change/reference the correct database that your queries will run against.SQLCMD -S PC\SQLEXPRESS -U sa -P admin -i C:\sqlquery.sql Once you get it working, change it and run it using a user with less permissions. Using sa where sa is not required is highly undesirable. |
 |
|
|
leite333
Starting Member
8 Posts |
Posted - 2011-08-02 : 00:50:22
|
| Hi again. Well it opens the monitor of command prompt very fast and i cant see what it says...how i can pause it?????? Also i did the syntax you said and more spesific my bat file is:SQLCMD -U sa -P admin -S USER-PC -d DATA -i C:\sqlquery.sqlwhere is DATA is the database.Also my query is very simple: INSERT INTO E1 (FULLNAME) VALUES ('TEST');As i see fast in command prompt it says that cannot execute something like that..How i can pause command prompt??? Also i notice that when i run the bat file then my sqlquery become empty..All that happens at windows 7 64 bitI wanna add here that in windows xp it worksWhen i do all that inside command prompt or sqlexpress everything worksAny ideas? |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-08-02 : 06:53:56
|
| Open a command window (Start->Run, type in cmd and click OK). In the command window change directory to the location where you have the bat file and type the name of the bat file to run it. That will let you observe the error messages.I suspect it may have something to do with SQLCMD not being in the path or not being installed on the Windows7 box. |
 |
|
|
|
|
|