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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 BCP command from .Net application

Author  Topic 

Babaksql
Starting Member

32 Posts

Posted - 2006-04-09 : 07:33:38
I have a simple BCP command to read data and store them in a text file.
it works fine when I'm runing it in query analyzer. However, when I try to run it from my VB.Net application by the ExecuteNonQuery statement, nothing happens.

Do you know why? that's urgent to me
Cheers

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-04-09 : 08:21:24
don't cross post http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64392
it's not polite.

is there any error you get??

Go with the flow & have fun! Else fight the flow
Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"]
Go to Top of Page

Babaksql
Starting Member

32 Posts

Posted - 2006-04-09 : 08:28:31
No, I dont get any error.
The statement runs well, but no text file is generated, there is no output.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-04-09 : 08:39:38
bcp is a command line utility. how do you run it?

Go with the flow & have fun! Else fight the flow
Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"]
Go to Top of Page

Babaksql
Starting Member

32 Posts

Posted - 2006-04-09 : 08:53:32
Suppose the pubs DB and authors Table
That's the code in query analyzer, text file is generated based on the time(c:\authors_..)

DECLARE @FileName varchar(50), @bcpCommand varchar(2000)
SET @FileName = REPLACE('c:\authors_'+CONVERT(char(8),GETDATE(),1)+'.txt','/','-')
SET @bcpCommand = 'bcp "SELECT * FROM pubs..authors ORDER BY au_lname" queryout '
SET @bcpCommand = @bcpCommand + @FileName + ' -c'
EXEC master..xp_cmdshell @bcpCommand


That's my simple code(cmdstr is a string with above content)

Dim Cmd As SqlClient.SqlCommand
Cmd = New System.Data.SqlClient.SqlCommand(cmdstr, Myconnection)
Cmd.ExecuteNonQuery()

After runing the program, there is no error. However there is no text file as well.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-04-09 : 09:30:17
Maybe the user you are connecting as doesn't have permission on the table (or xp_cmdshell but I would expect that to give an error).
Use the profiler to see what is actually being executed.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Babaksql
Starting Member

32 Posts

Posted - 2006-04-10 : 02:40:32
I have checke the user permisson and gave the right to run xp_cmdshell before.
Go to Top of Page

akumar
Starting Member

1 Post

Posted - 2006-04-27 : 04:37:50
Does your directory name start with "t". What happens is - when you specify a directory path as "C:\test" - it is read as "C: est". "\t" is converted to tab.

quote:
Originally posted by Babaksql

I have checke the user permisson and gave the right to run xp_cmdshell before.


Go to Top of Page
   

- Advertisement -