Question

for whatever reason, when I get to the step where I generate a txt file with data from a query using the BCP utility, it hangs on the file creation. then if i try to query the database for those tables, it really won't let me.

does anyone know why this would happen? the query is actually very simple:

SET @cmdQueryout = 'bcp "SELECT X FROM Database.dbo.Details WHERE DetailsId = (SELECT MAX(DetailsId) FROM Database.dbo.Details WHERE CommitDateTime IS NOT NULL AND LEFT(PolicyNumber, 3) != ''NYD'') ORDER BY X, Y, Z" queryout "' + @detailFilePath + '" -c -T'

EXEC master..xp_cmdshell @cmdQueryout  

I can see it created the first file but there's no data in it and it stops there.

I can open the file but if I try to delete, it won't let me because BCP is using the file.

The query should not take more than a few seconds to run so why would it stop like this?

EDIT - If I run this by itself in another query window, it works.

But if it's in a SQL job and in a transaction, it does not work.

Was it helpful?

Solution

Found out the issue.

I was using a trusted connection when I needed to specify a username & password.

-Uusername -Ppassword

instead of -T.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top