显示标签为“execute”的博文。显示所有博文
显示标签为“execute”的博文。显示所有博文

2012年3月29日星期四

bcp, queryout and pipe delimiter

When I execute the following string within a stored procedure:
(The string has been modified to mask company info)

bcp "Exec dbname.dbo.GetSalesCodesContracts" queryout d:\ftp\sfa\SalescodeContract-1.txt -m1 -c -t| -Uxxxxx -Pxxxxx -Sxxxxx

I get the following error: The name specified is not recognized as an
internal or external command, operable program or batch file.

But if I change -t| to -t, (comma) it works ok and produces a comma delimited file.

The pipe character seems to be the problem. The help file on delimiters says you can use the pipe.

This is running under SQL Server 7.0.

Any help would be appreciated.

RichardAre you using bulk insert or the bcp command line utility?

'|' is used for command line re-direction, most commonly to more, find and sort. It can also be used to re-direct the output of one application to another application. I suspect the command interpriter sees the '|' and tries to re-direct the result of your bcp command to the '-UXXXXX' application which as you have found out does not exist.

Hope this helped.|||Try using -t'|'|||Try using -t'|'

This did not work for me. Instead, I finally discovered, -t^| did the trick. (The DOS shell interpreter uses the ^ character to escape the | and interpret the whole thing as a literal to be passed to bcp, rather than as part of the DOS commandline itself.)|||I would do this with t-sql and xp_cmdshellsql

2012年3月27日星期二

BCP within a transaction

Hi guys
I have a small problem. I want to use BCP with in a transaction it's this
first I execute a SQL Statement against the database and delete some data,
then
I run the BCP utility.
my problem is how to use these two with in a single transaction!
please help me
I appreciate your help and time!
thanks,
-ArunaI haven't tested it myself, but see if BULK INSERT is usable in a transactio
n.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Aruna Tennakoon" <aruna.tennakoon@.gmail.com> wrote in message
news:%23L2k7OdWFHA.3840@.tk2msftngp13.phx.gbl...
> Hi guys
> I have a small problem. I want to use BCP with in a transaction it's this
> first I execute a SQL Statement against the database and delete some data,
> then
> I run the BCP utility.
> my problem is how to use these two with in a single transaction!
> please help me
> I appreciate your help and time!
> thanks,
> -Aruna
>|||Hi Tibor,
Thanks for your reply. I tried the BULK INSERT statment but, it didn't work
because it need the text file in the SQL Server.I am using client PC to do
this.
Please send me if you have any sample.
Thanks again
-Aruna
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OY36rDfWFHA.3760@.TK2MSFTNGP15.phx.gbl...
>I haven't tested it myself, but see if BULK INSERT is usable in a
>transaction.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Aruna Tennakoon" <aruna.tennakoon@.gmail.com> wrote in message
> news:%23L2k7OdWFHA.3840@.tk2msftngp13.phx.gbl...
>

2012年3月19日星期一

BCP in xp_cmdshell

Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
exec xp_cmdshell 'bcp '
It gives me generic usage message like
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-6 6x file format] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"]
EXCEPT in one server where I get the error below when executed through
xp_cmdshell (works fine in Command Prompt)
'bcp' is not recognized as an internal or external command,
operable program or batch file.
NULL
I am not using any account to run the SQL Server services.
Anyone, any idea?
--
Regards,
MZeeshanYou're going to need to give SQL Server more info to go on.
> exec xp_cmdshell 'bcp '
You need to specify "in","out",where the file is, etc. That's what the
generic message is telling you.
"MZeeshan" <mzeeshan@.community.nospam> wrote in message
news:3980BBF1-688F-48EB-9BE3-7EBF6DFB0B4C@.microsoft.com...
> Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> exec xp_cmdshell 'bcp '
> It gives me generic usage message like
> usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> [-m maxerrors] [-f formatfile] [-e errfile]
> [-F firstrow] [-L lastrow] [-b batchsize]
> [-n native type] [-c character type] [-w wide character type]
> [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> [-C code page specifier] [-t field terminator] [-r row terminator]
> [-i inputfile] [-o outfile] [-a packetsize]
> [-S server name] [-U username] [-P password]
> [-T trusted connection] [-v version] [-R regional enable]
> [-k keep null values] [-E keep identity values]
> [-h "load hints"]
> EXCEPT in one server where I get the error below when executed through
> xp_cmdshell (works fine in Command Prompt)
> 'bcp' is not recognized as an internal or external command,
> operable program or batch file.
> NULL
> I am not using any account to run the SQL Server services.
> Anyone, any idea?
> --
> Regards,
> MZeeshan|||I was just trying to give the simplest of the bcp options. Here, I was just
trying to explain there is some PATH issue in the shell when bcp is executed
from xp_cmdshell.
Regards,
MZeeshan
"ChrisR" wrote:
> You're going to need to give SQL Server more info to go on.
> > exec xp_cmdshell 'bcp '
> You need to specify "in","out",where the file is, etc. That's what the
> generic message is telling you.
>
> "MZeeshan" <mzeeshan@.community.nospam> wrote in message
> news:3980BBF1-688F-48EB-9BE3-7EBF6DFB0B4C@.microsoft.com...
> > Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> >
> > exec xp_cmdshell 'bcp '
> >
> > It gives me generic usage message like
> >
> > usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> > [-m maxerrors] [-f formatfile] [-e errfile]
> > [-F firstrow] [-L lastrow] [-b batchsize]
> > [-n native type] [-c character type] [-w wide character type]
> > [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> > [-C code page specifier] [-t field terminator] [-r row terminator]
> > [-i inputfile] [-o outfile] [-a packetsize]
> > [-S server name] [-U username] [-P password]
> > [-T trusted connection] [-v version] [-R regional enable]
> > [-k keep null values] [-E keep identity values]
> > [-h "load hints"]
> >
> > EXCEPT in one server where I get the error below when executed through
> > xp_cmdshell (works fine in Command Prompt)
> >
> > 'bcp' is not recognized as an internal or external command,
> > operable program or batch file.
> > NULL
> >
> > I am not using any account to run the SQL Server services.
> >
> > Anyone, any idea?
> >
> > --
> > Regards,
> > MZeeshan
>
>|||May be the binn (example: C:\Program Files\Microsoft SQL
Server\80\Tools\BINN) directory is not in the os variable "path" and
xp_cmdshell is trying to execute the cmd from another dir.
AMB
"MZeeshan" wrote:
> Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> exec xp_cmdshell 'bcp '
> It gives me generic usage message like
> usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> [-m maxerrors] [-f formatfile] [-e errfile]
> [-F firstrow] [-L lastrow] [-b batchsize]
> [-n native type] [-c character type] [-w wide character type]
> [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> [-C code page specifier] [-t field terminator] [-r row terminator]
> [-i inputfile] [-o outfile] [-a packetsize]
> [-S server name] [-U username] [-P password]
> [-T trusted connection] [-v version] [-R regional enable]
> [-k keep null values] [-E keep identity values]
> [-h "load hints"]
> EXCEPT in one server where I get the error below when executed through
> xp_cmdshell (works fine in Command Prompt)
> 'bcp' is not recognized as an internal or external command,
> operable program or batch file.
> NULL
> I am not using any account to run the SQL Server services.
> Anyone, any idea?
> --
> Regards,
> MZeeshan|||I have checked the path is present in the PATH variable in System Variables.
Plus, I can run bcp in Command Prompt
--
Regards,
MZeeshan
"Alejandro Mesa" wrote:
> May be the binn (example: C:\Program Files\Microsoft SQL
> Server\80\Tools\BINN) directory is not in the os variable "path" and
> xp_cmdshell is trying to execute the cmd from another dir.
>
> AMB
> "MZeeshan" wrote:
> > Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> >
> > exec xp_cmdshell 'bcp '
> >
> > It gives me generic usage message like
> >
> > usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> > [-m maxerrors] [-f formatfile] [-e errfile]
> > [-F firstrow] [-L lastrow] [-b batchsize]
> > [-n native type] [-c character type] [-w wide character type]
> > [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> > [-C code page specifier] [-t field terminator] [-r row terminator]
> > [-i inputfile] [-o outfile] [-a packetsize]
> > [-S server name] [-U username] [-P password]
> > [-T trusted connection] [-v version] [-R regional enable]
> > [-k keep null values] [-E keep identity values]
> > [-h "load hints"]
> >
> > EXCEPT in one server where I get the error below when executed through
> > xp_cmdshell (works fine in Command Prompt)
> >
> > 'bcp' is not recognized as an internal or external command,
> > operable program or batch file.
> > NULL
> >
> > I am not using any account to run the SQL Server services.
> >
> > Anyone, any idea?
> >
> > --
> > Regards,
> > MZeeshan|||Can you run this statement from QA?
exec master..xp_cmdshell 'path && cd'
> I have checked the path is present in the PATH variable in System Variables.
> Plus, I can run bcp in Command Prompt
How are accesing the command prompt?
AMB
"MZeeshan" wrote:
> I have checked the path is present in the PATH variable in System Variables.
> Plus, I can run bcp in Command Prompt
> --
> Regards,
> MZeeshan
>
> "Alejandro Mesa" wrote:
> > May be the binn (example: C:\Program Files\Microsoft SQL
> > Server\80\Tools\BINN) directory is not in the os variable "path" and
> > xp_cmdshell is trying to execute the cmd from another dir.
> >
> >
> > AMB
> >
> > "MZeeshan" wrote:
> >
> > > Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> > >
> > > exec xp_cmdshell 'bcp '
> > >
> > > It gives me generic usage message like
> > >
> > > usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> > > [-m maxerrors] [-f formatfile] [-e errfile]
> > > [-F firstrow] [-L lastrow] [-b batchsize]
> > > [-n native type] [-c character type] [-w wide character type]
> > > [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> > > [-C code page specifier] [-t field terminator] [-r row terminator]
> > > [-i inputfile] [-o outfile] [-a packetsize]
> > > [-S server name] [-U username] [-P password]
> > > [-T trusted connection] [-v version] [-R regional enable]
> > > [-k keep null values] [-E keep identity values]
> > > [-h "load hints"]
> > >
> > > EXCEPT in one server where I get the error below when executed through
> > > xp_cmdshell (works fine in Command Prompt)
> > >
> > > 'bcp' is not recognized as an internal or external command,
> > > operable program or batch file.
> > > NULL
> > >
> > > I am not using any account to run the SQL Server services.
> > >
> > > Anyone, any idea?
> > >
> > > --
> > > Regards,
> > > MZeeshan|||Thanks... this indeed worked.
What I found out that due to re-installation of SQL Server, the path
'c:\program files..\binn' has been pushed to the end and it was not appearing
in the xp_cmdshell 'path'.
Once the change was made, I had to reboot the server (just merely
stopping/restarting SQL server didn't help).
It's fine now!!!
--
Regards,
MZeeshan
"Alejandro Mesa" wrote:
> Can you run this statement from QA?
> exec master..xp_cmdshell 'path && cd'
> > I have checked the path is present in the PATH variable in System Variables.
> > Plus, I can run bcp in Command Prompt
> How are accesing the command prompt?
>
> AMB
> "MZeeshan" wrote:
> > I have checked the path is present in the PATH variable in System Variables.
> > Plus, I can run bcp in Command Prompt
> >
> > --
> > Regards,
> > MZeeshan
> >
> >
> > "Alejandro Mesa" wrote:
> >
> > > May be the binn (example: C:\Program Files\Microsoft SQL
> > > Server\80\Tools\BINN) directory is not in the os variable "path" and
> > > xp_cmdshell is trying to execute the cmd from another dir.
> > >
> > >
> > > AMB
> > >
> > > "MZeeshan" wrote:
> > >
> > > > Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> > > >
> > > > exec xp_cmdshell 'bcp '
> > > >
> > > > It gives me generic usage message like
> > > >
> > > > usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> > > > [-m maxerrors] [-f formatfile] [-e errfile]
> > > > [-F firstrow] [-L lastrow] [-b batchsize]
> > > > [-n native type] [-c character type] [-w wide character type]
> > > > [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> > > > [-C code page specifier] [-t field terminator] [-r row terminator]
> > > > [-i inputfile] [-o outfile] [-a packetsize]
> > > > [-S server name] [-U username] [-P password]
> > > > [-T trusted connection] [-v version] [-R regional enable]
> > > > [-k keep null values] [-E keep identity values]
> > > > [-h "load hints"]
> > > >
> > > > EXCEPT in one server where I get the error below when executed through
> > > > xp_cmdshell (works fine in Command Prompt)
> > > >
> > > > 'bcp' is not recognized as an internal or external command,
> > > > operable program or batch file.
> > > > NULL
> > > >
> > > > I am not using any account to run the SQL Server services.
> > > >
> > > > Anyone, any idea?
> > > >
> > > > --
> > > > Regards,
> > > > MZeeshan

BCP in xp_cmdshell

Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
exec xp_cmdshell 'bcp '
It gives me generic usage message like
usage: bcp {dbtable | query} {in | out | queryout | format} datafi
le
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide charact
er type]
[-N keep non-text native] [-6 6x file format] [-q quoted ident
ifier]
[-C code page specifier] [-t field terminator] [-r row terminat
or]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional ena
ble]
[-k keep null values] [-E keep identity values]
[-h "load hints"]
EXCEPT in one server where I get the error below when executed through
xp_cmdshell (works fine in Command Prompt)
'bcp' is not recognized as an internal or external command,
operable program or batch file.
NULL
I am not using any account to run the SQL Server services.
Anyone, any idea?
Regards,
MZeeshanYou're going to need to give SQL Server more info to go on.
> exec xp_cmdshell 'bcp '
You need to specify "in","out",where the file is, etc. That's what the
generic message is telling you.
"MZeeshan" <mzeeshan@.community.nospam> wrote in message
news:3980BBF1-688F-48EB-9BE3-7EBF6DFB0B4C@.microsoft.com...
> Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> exec xp_cmdshell 'bcp '
> It gives me generic usage message like
> usage: bcp {dbtable | query} {in | out | queryout | format} data
file
> [-m maxerrors] [-f formatfile] [-e errfile]
> [-F firstrow] [-L lastrow] [-b batchsize
]
> [-n native type] [-c character type] [-w wide char
acter type]
> [-N keep non-text native] [-6 6x file format] [-q quoted id
entifier]
> [-C code page specifier] [-t field terminator] [-r row termi
nator]
> [-i inputfile] [-o outfile] [-a packetsiz
e]
> [-S server name] [-U username] [-P password]
> [-T trusted connection] [-v version] [-R regional
enable]
> [-k keep null values] [-E keep identity values]
> [-h "load hints"]
> EXCEPT in one server where I get the error below when executed through
> xp_cmdshell (works fine in Command Prompt)
> 'bcp' is not recognized as an internal or external command,
> operable program or batch file.
> NULL
> I am not using any account to run the SQL Server services.
> Anyone, any idea?
> --
> Regards,
> MZeeshan|||I was just trying to give the simplest of the bcp options. Here, I was just
trying to explain there is some PATH issue in the shell when bcp is executed
from xp_cmdshell.
Regards,
MZeeshan
"ChrisR" wrote:

> You're going to need to give SQL Server more info to go on.
> You need to specify "in","out",where the file is, etc. That's what the
> generic message is telling you.
>
> "MZeeshan" <mzeeshan@.community.nospam> wrote in message
> news:3980BBF1-688F-48EB-9BE3-7EBF6DFB0B4C@.microsoft.com...
>
>|||May be the binn (example: C:\Program Files\Microsoft SQL
Server\80\Tools\BINN) directory is not in the os variable "path" and
xp_cmdshell is trying to execute the cmd from another dir.
AMB
"MZeeshan" wrote:

> Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> exec xp_cmdshell 'bcp '
> It gives me generic usage message like
> usage: bcp {dbtable | query} {in | out | queryout | format} data
file
> [-m maxerrors] [-f formatfile] [-e errfile]
> [-F firstrow] [-L lastrow] [-b batchsiz
e]
> [-n native type] [-c character type] [-w wide cha
racter type]
> [-N keep non-text native] [-6 6x file format] [-q quoted i
dentifier]
> [-C code page specifier] [-t field terminator] [-r row term
inator]
> [-i inputfile] [-o outfile] [-a packetsi
ze]
> [-S server name] [-U username] [-P password
]
> [-T trusted connection] [-v version] [-R regional
enable]
> [-k keep null values] [-E keep identity values]
> [-h "load hints"]
> EXCEPT in one server where I get the error below when executed through
> xp_cmdshell (works fine in Command Prompt)
> 'bcp' is not recognized as an internal or external command,
> operable program or batch file.
> NULL
> I am not using any account to run the SQL Server services.
> Anyone, any idea?
> --
> Regards,
> MZeeshan|||I have checked the path is present in the PATH variable in System Variables.
Plus, I can run bcp in Command Prompt
Regards,
MZeeshan
"Alejandro Mesa" wrote:
[vbcol=seagreen]
> May be the binn (example: C:\Program Files\Microsoft SQL
> Server\80\Tools\BINN) directory is not in the os variable "path" and
> xp_cmdshell is trying to execute the cmd from another dir.
>
> AMB
> "MZeeshan" wrote:
>|||Can you run this statement from QA?
exec master..xp_cmdshell 'path && cd'

> I have checked the path is present in the PATH variable in System Variable
s.
> Plus, I can run bcp in Command Prompt
How are accesing the command prompt?
AMB
"MZeeshan" wrote:
[vbcol=seagreen]
> I have checked the path is present in the PATH variable in System Variable
s.
> Plus, I can run bcp in Command Prompt
> --
> Regards,
> MZeeshan
>
> "Alejandro Mesa" wrote:
>|||Thanks... this indeed worked.
What I found out that due to re-installation of SQL Server, the path
'c:\program files..\binn' has been pushed to the end and it was not appearin
g
in the xp_cmdshell 'path'.
Once the change was made, I had to reboot the server (just merely
stopping/restarting SQL server didn't help).
It's fine now!!!
Regards,
MZeeshan
"Alejandro Mesa" wrote:
[vbcol=seagreen]
> Can you run this statement from QA?
> exec master..xp_cmdshell 'path && cd'
>
> How are accesing the command prompt?
>
> AMB
> "MZeeshan" wrote:
>

BCP in xp_cmdshell

Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
exec xp_cmdshell 'bcp '
It gives me generic usage message like
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-6 6x file format] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"]
EXCEPT in one server where I get the error below when executed through
xp_cmdshell (works fine in Command Prompt)
'bcp' is not recognized as an internal or external command,
operable program or batch file.
NULL
I am not using any account to run the SQL Server services.
Anyone, any idea?
Regards,
MZeeshan
You're going to need to give SQL Server more info to go on.
> exec xp_cmdshell 'bcp '
You need to specify "in","out",where the file is, etc. That's what the
generic message is telling you.
"MZeeshan" <mzeeshan@.community.nospam> wrote in message
news:3980BBF1-688F-48EB-9BE3-7EBF6DFB0B4C@.microsoft.com...
> Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> exec xp_cmdshell 'bcp '
> It gives me generic usage message like
> usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> [-m maxerrors] [-f formatfile] [-e errfile]
> [-F firstrow] [-L lastrow] [-b batchsize]
> [-n native type] [-c character type] [-w wide character type]
> [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> [-C code page specifier] [-t field terminator] [-r row terminator]
> [-i inputfile] [-o outfile] [-a packetsize]
> [-S server name] [-U username] [-P password]
> [-T trusted connection] [-v version] [-R regional enable]
> [-k keep null values] [-E keep identity values]
> [-h "load hints"]
> EXCEPT in one server where I get the error below when executed through
> xp_cmdshell (works fine in Command Prompt)
> 'bcp' is not recognized as an internal or external command,
> operable program or batch file.
> NULL
> I am not using any account to run the SQL Server services.
> Anyone, any idea?
> --
> Regards,
> MZeeshan
|||I was just trying to give the simplest of the bcp options. Here, I was just
trying to explain there is some PATH issue in the shell when bcp is executed
from xp_cmdshell.
Regards,
MZeeshan
"ChrisR" wrote:

> You're going to need to give SQL Server more info to go on.
> You need to specify "in","out",where the file is, etc. That's what the
> generic message is telling you.
>
> "MZeeshan" <mzeeshan@.community.nospam> wrote in message
> news:3980BBF1-688F-48EB-9BE3-7EBF6DFB0B4C@.microsoft.com...
>
>
|||May be the binn (example: C:\Program Files\Microsoft SQL
Server\80\Tools\BINN) directory is not in the os variable "path" and
xp_cmdshell is trying to execute the cmd from another dir.
AMB
"MZeeshan" wrote:

> Whenever I execute 'bcp' in Command Prompt or in xp_cmdshell such as
> exec xp_cmdshell 'bcp '
> It gives me generic usage message like
> usage: bcp {dbtable | query} {in | out | queryout | format} datafile
> [-m maxerrors] [-f formatfile] [-e errfile]
> [-F firstrow] [-L lastrow] [-b batchsize]
> [-n native type] [-c character type] [-w wide character type]
> [-N keep non-text native] [-6 6x file format] [-q quoted identifier]
> [-C code page specifier] [-t field terminator] [-r row terminator]
> [-i inputfile] [-o outfile] [-a packetsize]
> [-S server name] [-U username] [-P password]
> [-T trusted connection] [-v version] [-R regional enable]
> [-k keep null values] [-E keep identity values]
> [-h "load hints"]
> EXCEPT in one server where I get the error below when executed through
> xp_cmdshell (works fine in Command Prompt)
> 'bcp' is not recognized as an internal or external command,
> operable program or batch file.
> NULL
> I am not using any account to run the SQL Server services.
> Anyone, any idea?
> --
> Regards,
> MZeeshan
|||I have checked the path is present in the PATH variable in System Variables.
Plus, I can run bcp in Command Prompt
Regards,
MZeeshan
"Alejandro Mesa" wrote:
[vbcol=seagreen]
> May be the binn (example: C:\Program Files\Microsoft SQL
> Server\80\Tools\BINN) directory is not in the os variable "path" and
> xp_cmdshell is trying to execute the cmd from another dir.
>
> AMB
> "MZeeshan" wrote:
|||Can you run this statement from QA?
exec master..xp_cmdshell 'path && cd'

> I have checked the path is present in the PATH variable in System Variables.
> Plus, I can run bcp in Command Prompt
How are accesing the command prompt?
AMB
"MZeeshan" wrote:
[vbcol=seagreen]
> I have checked the path is present in the PATH variable in System Variables.
> Plus, I can run bcp in Command Prompt
> --
> Regards,
> MZeeshan
>
> "Alejandro Mesa" wrote:
|||Thanks... this indeed worked.
What I found out that due to re-installation of SQL Server, the path
'c:\program files..\binn' has been pushed to the end and it was not appearing
in the xp_cmdshell 'path'.
Once the change was made, I had to reboot the server (just merely
stopping/restarting SQL server didn't help).
It's fine now!!!
Regards,
MZeeshan
"Alejandro Mesa" wrote:
[vbcol=seagreen]
> Can you run this statement from QA?
> exec master..xp_cmdshell 'path && cd'
>
> How are accesing the command prompt?
>
> AMB
> "MZeeshan" wrote:

2012年3月8日星期四

bcp Format files help?

I am using bcp to execute a query and would like to use the -f option for format_file so I am going thourgh the books on line and trying to make some sense out of it,no quite clear on it at the moment.

How do I find out the version of bcp utility and would somebody have an example with this options just to see how it works.

ThanksFormat files? Jeez, it's been a while...

As I recall there is an option you can include that will create a format file for you. Run the BCP once with this option and then edit the file it creates. That's the LAZY DBA way...|||You can "cook your own" sample using something like:bcp master.dbo.sysdatabases format sd.dat -Usa -c -SC1126582-B -fsd.fmtThis will create a format file that is properly formatted for the source table, using conventional character output.

A lazy dba is a good dba!

-PatP|||What the hell is -B?|||What the hell is -B?Part of the workstation name, not a parameter!

-PatP

2012年3月6日星期二

BCP Errors

I execute a store procedure like
Sploadnew 'may'
The may is char type which is converted to a datetime and the query is
something like and I create a tem table
SELECT into ##tetable SUM(sales)+SUM(sales1)
FROM table
group by state
where datepart(mm,prod_date)=datepart(mm,@.datenew)
I want to BCP this result to a server location from within the store
procedure and I did
exec master..xp_cmdshell BCP ##tetable
OUT "//server/folder/rsult.txt"
-S server
-U sa
-P Password
I get this error
erver: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '##tetable'
what is wrong in this approach
Any Answers?I'm not quite sure where the error is occurring here, but
one way to help to determine this is instead of using the
actual BCP command syntax within the xp_cmdshell call
(which may be what is causing the SQL parser to find an
error), put your BCP command in a Windows NT .cmd command
file. Then use xp_cmdshell to execute this .cmd file.
This should eliminate any wacky allowable syntax
differences between what BCP allows and what the SQL
parser allows.
Also, I don't know if you left this out just in your post
or if you left it out in your stored proc, but you might
want to try enclosing the entire BCP command syntax in
single quotes:
exec master..xp_cmdshell 'BCP ##tetable
OUT "//server/folder/rsult.txt"
-S server
-U sa
-P Password'
generally, with xp_cmdshell, if your command syntax
includes spaces, the commnad syntax needs to be within
single quotes.
I hope that this helps.
Matthew Bando
BandoM@.CSCTechnologies (remove) . com
>--Original Message--
>I execute a store procedure like
>Sploadnew 'may'
>The may is char type which is converted to a datetime
and the query is
>something like and I create a tem table
>SELECT into ##tetable SUM(sales)+SUM(sales1)
>FROM table
>group by state
>where datepart(mm,prod_date)=datepart(mm,@.datenew)
>I want to BCP this result to a server location from
within the store
>procedure and I did
>exec master..xp_cmdshell BCP ##tetable
>OUT "//server/folder/rsult.txt"
>-S server
>-U sa
>-P Password
> I get this error
>erver: Msg 170, Level 15, State 1, Line 1
>Line 1: Incorrect syntax near '##tetable'
>what is wrong in this approach
>Any Answers?
>
>.
>

BCP Error

Hi All,
I am getting the following error when I execute the following BCP command fr
om query analyser.
BCP Command
=========
xp_cmdshell 'c:\MSSQL7\BINN\BCP SQLManager.dbo.z_DBAdmin_Fwd_MAXDRBUS02_DBAd
min_dbo_tbl_CheckServerRoleMembers_20040
331161058 in "c:\Temp\DBAdmin_Fwd_MA
XDRBUS02_DBAdmin_tbl_CheckServerRoleMemb
ers.bcp" /S204.5.2.11,1942 /UDBAdmi
nUser /PDtyrimby0 /c /b1000
/m1'
Error
===
xp_cmdshell 'c:\MSSQL7\BINN\BCP SQLManager.dbo.z_DBAdmin_Fwd_MAXDRBUS02_DBAd
min_dbo_tbl_CheckServerRoleMembers_20040
331161058 in "c:\Temp\DBAdmin_Fwd_MA
XDRBUS02_DBAdmin_tbl_CheckServerRoleMemb
ers.bcp" /S204.5.2.11,1942 /UDBAdmi
nUser /PDtyrimby0 /c /b1000
/m1'
Can any help me how solve this problem
Thanks & Regards
BalajiHi,
Replace '/' with '-' (Hyphen) in the BCP command.
-S204.5.2.11,1942 -UDBAdminUser -PDtyrimby0 -c -b1000 -m1
Thanks
Hari
MCDBA
"Balaji" <anonymous@.discussions.microsoft.com> wrote in message
news:4C7F90DC-EDAB-474A-B62E-5E6C72700BD8@.microsoft.com...
> Hi All,
> I am getting the following error when I execute the following BCP command
from query analyser.
> BCP Command
> =========
> xp_cmdshell 'c:\MSSQL7\BINN\BCP
SQLManager.dbo. z_DBAdmin_Fwd_MAXDRBUS02_DBAdmin_dbo_tbl
_CheckServerRoleMembe
rs_20040331161058 in
" c:\Temp\DBAdmin_Fwd_MAXDRBUS02_DBAdmin_t
bl_CheckServerRoleMembers.bcp"
/S204.5.2.11,1942 /UDBAdminUser /PDtyrimby0 /c /b1000 /m1'
> Error
> ===
> xp_cmdshell 'c:\MSSQL7\BINN\BCP
SQLManager.dbo. z_DBAdmin_Fwd_MAXDRBUS02_DBAdmin_dbo_tbl
_CheckServerRoleMembe
rs_20040331161058 in
" c:\Temp\DBAdmin_Fwd_MAXDRBUS02_DBAdmin_t
bl_CheckServerRoleMembers.bcp"
/S204.5.2.11,1942 /UDBAdminUser /PDtyrimby0 /c /b1000 /m1'
> Can any help me how solve this problem
> Thanks & Regards
> Balaji

2012年2月23日星期四

bcp API

I would like to execute bulk copy functionality from a C++ app. Does
an API exist? I have found Bulk-Copy functions (bcp_init,
bcp_exe...) in the ODBC API, is this what I should use? And if yes,
will/is it support by SQL Server version after SQL Server 2000?

Thanks!"elizabeth" <ezelasky@.hotmail.com> wrote in message
news:78393913.0410080650.16eb7a77@.posting.google.c om...
>I would like to execute bulk copy functionality from a C++ app. Does
> an API exist? I have found Bulk-Copy functions (bcp_init,
> bcp_exe...) in the ODBC API, is this what I should use? And if yes,
> will/is it support by SQL Server version after SQL Server 2000?
> Thanks!

Yes - see "Performing Bulk Copy Operations" in Books Online. ODBC is
supported in MSSQL 2005, and the same documentation appears in the latest
available version of the MSSQL 2005 BOL:

http://www.microsoft.com/downloads/...&DisplayLang=en

Simon|||With unmanaged C++ code, you might also consider OLE DB IRowsetFastLoad.
This is what DTS uses.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"elizabeth" <ezelasky@.hotmail.com> wrote in message
news:78393913.0410080650.16eb7a77@.posting.google.c om...
>I would like to execute bulk copy functionality from a C++ app. Does
> an API exist? I have found Bulk-Copy functions (bcp_init,
> bcp_exe...) in the ODBC API, is this what I should use? And if yes,
> will/is it support by SQL Server version after SQL Server 2000?
> Thanks!

bcp and xp_cmdshell

Hi Experts,
When I execute the command
"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp" "select Severity
from tempdb..EventsArchive" queryout
"c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210
From the command line the bcp works fine. (I need the full path for the
bcp because we have Sybase as well on the machine)
However, when I execute the code below it form a sp it fails.
declare @.statement varchar(2000)
set @.statement = '"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp"
"select Severity from tempdb..EventsArchive" queryout
c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210'
exec master..xp_cmdshell @.statement
Thanks,
Avi
Hi
What does BOL say about more than one double quote?
Syntax
xp_cmdshell {'command_string'} [, no_output]
Arguments
'command_string'
Is the command string to execute at the operating-system command shell.
command_string is varchar(8000) or nvarchar(4000), with no default.
command_string cannot contain more than one set of double quotation marks. A
single pair of quotation marks is necessary if any spaces are present in the
file paths or program names referenced by command_string. If you have trouble
with embedded spaces, consider using FAT 8.3 file names as a workaround.
no_output
Is an optional parameter executing the given command_string, and does not
return any output to the client.
Regards
Mike
"Avi" wrote:

> Hi Experts,
> When I execute the command
> "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp" "select Severity
> from tempdb..EventsArchive" queryout
> "c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210
> From the command line the bcp works fine. (I need the full path for the
> bcp because we have Sybase as well on the machine)
> However, when I execute the code below it form a sp it fails.
> declare @.statement varchar(2000)
> set @.statement = '"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp"
> "select Severity from tempdb..EventsArchive" queryout
> c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210'
> exec master..xp_cmdshell @.statement
> Thanks,
> Avi
>
>
>
|||Hi Avi,
You can also use it the following way;
SET @.conn = '" -U <username> -P <pwd> -c'
SET @.filename = '\\servername\foldername\test'+'.txt')
SET @.sql1 = 'BCP "SELECT * FROM <table name>)" QUERYOUT "'
SET @.sql1 = @.sql1 + @.filename + @.conn
EXEC master..xp_cmdshell @.sql1
You don't have to give full path of BCP utility.
Thanks
Yogish

bcp and xp_cmdshell

Hi Experts,
When I execute the command
"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp" "select Severity
from tempdb..EventsArchive" queryout
"c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210
From the command line the bcp works fine. (I need the full path for the
bcp because we have Sybase as well on the machine)
However, when I execute the code below it form a sp it fails.
declare @.statement varchar(2000)
set @.statement = '"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp"
"select Severity from tempdb..EventsArchive" queryout
c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210'
exec master..xp_cmdshell @.statement
Thanks,
AviHi
What does BOL say about more than one double quote?
Syntax
xp_cmdshell {'command_string'} [, no_output]
Arguments
'command_string'
Is the command string to execute at the operating-system command shell.
command_string is varchar(8000) or nvarchar(4000), with no default.
command_string cannot contain more than one set of double quotation marks. A
single pair of quotation marks is necessary if any spaces are present in the
file paths or program names referenced by command_string. If you have troubl
e
with embedded spaces, consider using FAT 8.3 file names as a workaround.
no_output
Is an optional parameter executing the given command_string, and does not
return any output to the client.
Regards
Mike
"Avi" wrote:

> Hi Experts,
> When I execute the command
> "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp" "select Severity
> from tempdb..EventsArchive" queryout
> "c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210
> From the command line the bcp works fine. (I need the full path for the
> bcp because we have Sybase as well on the machine)
> However, when I execute the code below it form a sp it fails.
> declare @.statement varchar(2000)
> set @.statement = '"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp
"
> "select Severity from tempdb..EventsArchive" queryout
> c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210'
> exec master..xp_cmdshell @.statement
> Thanks,
> Avi
>
>
>|||Hi Avi,
You can also use it the following way;
SET @.conn = '" -U <username> -P <pwd> -c'
SET @.filename = '\\servername\foldername\test'+'.txt')
SET @.sql1 = 'BCP "SELECT * FROM <table name> )" QUERYOUT "'
SET @.sql1 = @.sql1 + @.filename + @.conn
EXEC master..xp_cmdshell @.sql1
You don't have to give full path of BCP utility.
Thanks
Yogish

bcp and xp_cmdshell

Hi Experts,
When I execute the command
"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp" "select Severity
from tempdb..EventsArchive" queryout
"c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210
From the command line the bcp works fine. (I need the full path for the
bcp because we have Sybase as well on the machine)
However, when I execute the code below it form a sp it fails.
declare @.statement varchar(2000)
set @.statement = '"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp"
"select Severity from tempdb..EventsArchive" queryout
c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210'
exec master..xp_cmdshell @.statement
Thanks,
AviHi
What does BOL say about more than one double quote?
Syntax
xp_cmdshell {'command_string'} [, no_output]
Arguments
'command_string'
Is the command string to execute at the operating-system command shell.
command_string is varchar(8000) or nvarchar(4000), with no default.
command_string cannot contain more than one set of double quotation marks. A
single pair of quotation marks is necessary if any spaces are present in the
file paths or program names referenced by command_string. If you have trouble
with embedded spaces, consider using FAT 8.3 file names as a workaround.
no_output
Is an optional parameter executing the given command_string, and does not
return any output to the client.
Regards
Mike
"Avi" wrote:
> Hi Experts,
> When I execute the command
> "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp" "select Severity
> from tempdb..EventsArchive" queryout
> "c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210
> From the command line the bcp works fine. (I need the full path for the
> bcp because we have Sybase as well on the machine)
> However, when I execute the code below it form a sp it fails.
> declare @.statement varchar(2000)
> set @.statement = '"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\bcp"
> "select Severity from tempdb..EventsArchive" queryout
> c:\aaabbbcc.txt" -c -t"," -C -Usa -P1210'
> exec master..xp_cmdshell @.statement
> Thanks,
> Avi
>
>
>|||Hi Avi,
You can also use it the following way;
SET @.conn = '" -U <username> -P <pwd> -c'
SET @.filename = '\\servername\foldername\test'+'.txt')
SET @.sql1 = 'BCP "SELECT * FROM <table name>)" QUERYOUT "'
SET @.sql1 = @.sql1 + @.filename + @.conn
EXEC master..xp_cmdshell @.sql1
You don't have to give full path of BCP utility.
--
Thanks
Yogish

bcp and transaction problem

Hi,
We are creating a procedure in which we use bcp
(xp_cmdshell) to archive out the data for particular
month. When I execute procedure without begin tran/commit
tran it works fine and bcp out the data from table to hard
disk. But when i try to use transaction handling using
begin tran i see it to be waiting and dbcc inputbuffer of
waiting process shows:
SET FMTONLY ON select * from db..bcptable SET FMTONLY OFF
Why sql server is starting seperate process within
procedure ...IS there any special way to handle
transaction when using bcp and xp_cmdshell in the
procedure?
This is the only procedure running on machine.
Thanks
--harvinderharvinder,
> We are creating a procedure in which we use bcp
> (xp_cmdshell) to archive out the data for particular
> month. When I execute procedure without begin tran/commit
> tran it works fine and bcp out the data from table to hard
> disk. But when i try to use transaction handling using
> begin tran i see it to be waiting and dbcc inputbuffer of
> waiting process shows:
> SET FMTONLY ON select * from db..bcptable SET FMTONLY OFF
> Why sql server is starting seperate process within
> procedure ...IS there any special way to handle
> transaction when using bcp and xp_cmdshell in the
> procedure?
Bcp is running as a separate connection, not as a part of your
transaction. This is normal. It is being blocked by the connection
that opened the transaction. You cannot wrap a call to bcp in a
transaction.
Linda

BCP and Stored Procedure

I am trying to use BCP to generate a textfile with the results of sp_help_revlogins.
xp_cmdshell 'bcp "execute sp_help_revlogin" queryout c:\test\test.txt -c -S"testserver" -U"sa" -P"test"'
The error I receive is the following:
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]BCP host-files must contain at least one column
I would appreciate any incite on the solution to this problem as well as the cause.
Thank you in advance.
Robert
If all you want is the output of sp_help_revlogin to be placed in a file try
using OSQL. Something like this:
OSQL -S<yourserver> -U<login> -P<password> -Q"exec
sp_help_revlogin" -oc:\test\test.txt
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Robert M." <Robert M.@.discussions.microsoft.com> wrote in message
news:0C360F11-4D5A-4BC4-976E-35650510E775@.microsoft.com...
> I am trying to use BCP to generate a textfile with the results of
sp_help_revlogins.
> xp_cmdshell 'bcp "execute sp_help_revlogin" queryout
c:\test\test.txt -c -S"testserver" -U"sa" -P"test"'
> The error I receive is the following:
> SQLState = S1000, NativeError = 0
> Error = [Microsoft][ODBC SQL Server Driver]BCP host-files must contain at
least one column
> I would appreciate any incite on the solution to this problem as well as
the cause.
> Thank you in advance.
> Robert
>
>
|||If all you want is the output of sp_help_revlogin to be placed in a file try
using OSQL. Something like this:
OSQL -S<yourserver> -U<login> -P<password> -Q"exec
sp_help_revlogin" -oc:\test\test.txt
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Robert M." <Robert M.@.discussions.microsoft.com> wrote in message
news:0C360F11-4D5A-4BC4-976E-35650510E775@.microsoft.com...
> I am trying to use BCP to generate a textfile with the results of
sp_help_revlogins.
> xp_cmdshell 'bcp "execute sp_help_revlogin" queryout
c:\test\test.txt -c -S"testserver" -U"sa" -P"test"'
> The error I receive is the following:
> SQLState = S1000, NativeError = 0
> Error = [Microsoft][ODBC SQL Server Driver]BCP host-files must contain at
least one column
> I would appreciate any incite on the solution to this problem as well as
the cause.
> Thank you in advance.
> Robert
>
>

BCP and Stored Procedure

I am trying to use BCP to generate a textfile with the results of sp_help_re
vlogins.
xp_cmdshell 'bcp "execute sp_help_revlogin" queryout c:\test\test.txt -c -S"
testserver" -U"sa" -P"test"'
The error I receive is the following:
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]BCP host-files must conta
in at least one column
I would appreciate any incite on the solution to this problem as well as the
cause.
Thank you in advance.
RobertIf all you want is the output of sp_help_revlogin to be placed in a file try
using OSQL. Something like this:
OSQL -S<yourserver> -U<login> -P<password> -Q"exec
sp_help_revlogin" -oc:\test\test.txt
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Robert M." <Robert M.@.discussions.microsoft.com> wrote in message
news:0C360F11-4D5A-4BC4-976E-35650510E775@.microsoft.com...
> I am trying to use BCP to generate a textfile with the results of
sp_help_revlogins.
> xp_cmdshell 'bcp "execute sp_help_revlogin" queryout
c:\test\test.txt -c -S"testserver" -U"sa" -P"test"'
> The error I receive is the following:
> SQLState = S1000, NativeError = 0
> Error = [Microsoft][ODBC SQL Server Driver]BCP host-files must contain at[
/vbcol]
least one column[vbcol=seagreen]
> I would appreciate any incite on the solution to this problem as well as
the cause.
> Thank you in advance.
> Robert
>
>

2012年2月13日星期一

Batch file call to SQL Agent to make Bakcup

Hello.
I've a Backup system that copies my files and I want to copy also my
SQL Server DDBB. I intend to execute the batch file before de File
Backup starts to call de SQL Agent so it makes those Backups and then
copy them to the Backup folder so the Backup system copies everything.
The problem is that I don't know if it is possible to call to the SQL
Agent through a Batch file to make these Backups. If so, how could I
do it?
Thank you.
One suggestion ... instead of having the batch file calling the SQL Agent,
you can use the OSQL utility (it is a command line utility for SQL). You can
backup the database using OSQL.
Thank you
Lucas
"Gurk" <gurkgamer@.gmail.com> wrote in message
news:1181666228.803256.267530@.d30g2000prg.googlegr oups.com...
> Hello.
> I've a Backup system that copies my files and I want to copy also my
> SQL Server DDBB. I intend to execute the batch file before de File
> Backup starts to call de SQL Agent so it makes those Backups and then
> copy them to the Backup folder so the Backup system copies everything.
> The problem is that I don't know if it is possible to call to the SQL
> Agent through a Batch file to make these Backups. If so, how could I
> do it?
> Thank you.
>
|||If the backup script is in a job, you can execute that job
through OSQL, SQLCMD, etc by executing sp_start_job. You can
find more information on sp_start_job in books online
-Sue
On Tue, 12 Jun 2007 09:37:08 -0700, Gurk
<gurkgamer@.gmail.com> wrote:

>Hello.
>I've a Backup system that copies my files and I want to copy also my
>SQL Server DDBB. I intend to execute the batch file before de File
>Backup starts to call de SQL Agent so it makes those Backups and then
>copy them to the Backup folder so the Backup system copies everything.
>The problem is that I don't know if it is possible to call to the SQL
>Agent through a Batch file to make these Backups. If so, how could I
>do it?
>Thank you.

Batch file call to SQL Agent to make Bakcup

Hello.
I've a Backup system that copies my files and I want to copy also my
SQL Server DDBB. I intend to execute the batch file before de File
Backup starts to call de SQL Agent so it makes those Backups and then
copy them to the Backup folder so the Backup system copies everything.
The problem is that I don't know if it is possible to call to the SQL
Agent through a Batch file to make these Backups. If so, how could I
do it?
Thank you.One suggestion ... instead of having the batch file calling the SQL Agent,
you can use the OSQL utility (it is a command line utility for SQL). You can
backup the database using OSQL.
Thank you
Lucas
"Gurk" <gurkgamer@.gmail.com> wrote in message
news:1181666228.803256.267530@.d30g2000prg.googlegroups.com...
> Hello.
> I've a Backup system that copies my files and I want to copy also my
> SQL Server DDBB. I intend to execute the batch file before de File
> Backup starts to call de SQL Agent so it makes those Backups and then
> copy them to the Backup folder so the Backup system copies everything.
> The problem is that I don't know if it is possible to call to the SQL
> Agent through a Batch file to make these Backups. If so, how could I
> do it?
> Thank you.
>|||If the backup script is in a job, you can execute that job
through OSQL, SQLCMD, etc by executing sp_start_job. You can
find more information on sp_start_job in books online
-Sue
On Tue, 12 Jun 2007 09:37:08 -0700, Gurk
<gurkgamer@.gmail.com> wrote:
>Hello.
>I've a Backup system that copies my files and I want to copy also my
>SQL Server DDBB. I intend to execute the batch file before de File
>Backup starts to call de SQL Agent so it makes those Backups and then
>copy them to the Backup folder so the Backup system copies everything.
>The problem is that I don't know if it is possible to call to the SQL
>Agent through a Batch file to make these Backups. If so, how could I
>do it?
>Thank you.

Batch file call to SQL Agent to make Bakcup

Hello.
I've a Backup system that copies my files and I want to copy also my
SQL Server DDBB. I intend to execute the batch file before de File
Backup starts to call de SQL Agent so it makes those Backups and then
copy them to the Backup folder so the Backup system copies everything.
The problem is that I don't know if it is possible to call to the SQL
Agent through a Batch file to make these Backups. If so, how could I
do it?
Thank you.One suggestion ... instead of having the batch file calling the SQL Agent,
you can use the OSQL utility (it is a command line utility for SQL). You can
backup the database using OSQL.
Thank you
Lucas
"Gurk" <gurkgamer@.gmail.com> wrote in message
news:1181666228.803256.267530@.d30g2000prg.googlegroups.com...
> Hello.
> I've a Backup system that copies my files and I want to copy also my
> SQL Server DDBB. I intend to execute the batch file before de File
> Backup starts to call de SQL Agent so it makes those Backups and then
> copy them to the Backup folder so the Backup system copies everything.
> The problem is that I don't know if it is possible to call to the SQL
> Agent through a Batch file to make these Backups. If so, how could I
> do it?
> Thank you.
>|||If the backup script is in a job, you can execute that job
through OSQL, SQLCMD, etc by executing sp_start_job. You can
find more information on sp_start_job in books online
-Sue
On Tue, 12 Jun 2007 09:37:08 -0700, Gurk
<gurkgamer@.gmail.com> wrote:

>Hello.
>I've a Backup system that copies my files and I want to copy also my
>SQL Server DDBB. I intend to execute the batch file before de File
>Backup starts to call de SQL Agent so it makes those Backups and then
>copy them to the Backup folder so the Backup system copies everything.
>The problem is that I don't know if it is possible to call to the SQL
>Agent through a Batch file to make these Backups. If so, how could I
>do it?
>Thank you.

2012年2月12日星期日

Batch execute of SQL script from ADO.Net

I have a VB.Net application that needs to create about 5 stored
procedures and a couple of functions on SQL Server 2005 Express.
Currently I can execute all of them in one window of Sql Server
Management Studio, just separate each of them with a "GO" statement. Is
there a way I can accomplish this "one shot" approach via ADO.Net in my
application? If so, I can just put all my ddl SQL code in a text file
as an embedded resource, and then execute it in a couple of lines of
code. However, I suspect that I need to execute each ddl statement
separately and thus will need to parse the text file to break it up, or
break the sql code into multiple files, one for each stored proc.
Thanks for your thoughts,
Marcus[Reposted, as posts from outside msnews.microsoft.com does not seem to make
it in.]
Marcus (holysmokes99@.hotmail.com) writes:
> I have a VB.Net application that needs to create about 5 stored
> procedures and a couple of functions on SQL Server 2005 Express.
> Currently I can execute all of them in one window of Sql Server
> Management Studio, just separate each of them with a "GO" statement. Is
> there a way I can accomplish this "one shot" approach via ADO.Net in my
> application? If so, I can just put all my ddl SQL code in a text file
> as an embedded resource, and then execute it in a couple of lines of
> code. However, I suspect that I need to execute each ddl statement
> separately and thus will need to parse the text file to break it up, or
> break the sql code into multiple files, one for each stored proc.
Yes, if you read this file from your own application, you will need to
parse the file for "go" and send down batch by batch with ExcecuteNonQuery.
Parsing the file for "go" is a trivial matter.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.seBooks Online for SQL
Server 2005
athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000
athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx