Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Script Connection Question

Status
Not open for further replies.

ianwin

Programmer
Jul 5, 2005
44
US
I am trying to run an insert statement into an SQL Server 2000 database from a .sql file which is being called from a batch file running on the same server as the database.

I have got the insert statement working when run from an interavtive SQL session, but I cannot get a connection from the .sql file to work.

Does anyone know what the syntaax is for connecting to an SQL 2000 database from a .sql file?

Thanks,
-Ian
 
Surely you will need to connect to a server before you can issue any sql.
Perhaps you could show the contents of your .bat file.
What version of SQL Server are you using?
 
Hi,

The batch file i'm using is:
Code:
for /f %%a IN ('dir /b *.csv') do svrmgrl @Insert.sql %%a

The Insert.sql file is:

Code:
BULK INSERT Table1
from %1
with
(
	FIELDTERMINATOR = ',',z
	ROWTERMINATOR = ',\n'
);

I am trying to work out the line which I am assuming comes before the insert statement which would open a connection ot the database.

e.g. The SQL Server equivalent of the oracle command

Code:
connect user\password@database

-Ian
 
Check OSQL command line utility. In general you could use it that way:
Code:
OSQL -S ServerName -U User -P Pass (or -E - trusted connection) -i YoursqlFile.SQL

For SQL Server 2000 that utility is in
\Program Files\Microsoft SQL Server\80\Tools\Binn\

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top