Export Using BCP with Query (QUERYOUT)

I want to export data from a database Azur to an Excel file. To do this, i use the command :

bcp [DatabaseName].[Table] OUT C:...\Test_Export.xls -c -U UserName@ServerName.database.windows.net -S tcp:ServerName.database.windows.net -P xxxxxxxx

--> It Works

BUT, when i want do the same with SQL Query in the command, like this :

bcp "Select field1, Field2 FROM [dbo].[ForecastTrialDisag]" QUERYOUT C:..\Test_Export.xls -d [DataBaseName] -c -U UserName@ServerName.database.windows.net -S tcp:ServerName.database.windows.net -P xxxxxx

I have errors :

SQLState = 37000, NativeError = 4060 Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "[DataBaseName]" requested by the login. The login failed.

SQLState = 28000, NativeError = 18456 Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'UserName'.

I don't understand why it doesn't work with a SQL query. UserName, databaseName and password are OK.

Thank you for your help,

Simon

December 16th, 2013 12:26pm

Hi,

This thread seems like SQL Azure issue, I will move this thread to SQL Azure forum for a better support.

Best Reagrds

Free Windows Admin Tool Kit Click here and download it now
December 17th, 2013 10:00am

Hello,

I try to reproduce the issue in my test environment, however, it is works well.
Based on your description, it seems that you use -d [databasename], how about just -d databasename ?
If the database name contains a space, based on the BCP utility: to specify a database name that contains a space or quotation mark, you must use the -q option.

Regards,
Fanny Liu

December 17th, 2013 2:07pm

Hello,

Thanks for your help.

I tri using the option -q, but it didn't work.

C:\Users\... >  bcp "SELECT TimeId,Quantity FROM [dbo].[Table]" QUERYOUT C:\Users\...\Desktop\Test_t.xls -q -d [XXXX.YYYY.ZZ] -c -U NameUser@ServerName -S tcp:SerName.database.windows.net -P xxxxxx

I have the error :

------------------------------------------------
SQLState = 37000, NativeError = 4060

Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "[XXXX.YYYY.ZZ]" requested by the login. The login failed.

------------------------------------------------------
SQLState = 28000, NativeError = 18456

Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NameUser'.

-------------------------------------------------------
SQLState = 01000, NativeError = 40608

Warning = [Microsoft][SQL Server Native Client 10.0][SQL Server]This session has
 been assigned a tracing ID of 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.  Provide
this tracing ID to customer support when you need assistance.

Any idea ?
Thanks for your help,

Simon

Free Windows Admin Tool Kit Click here and download it now
December 18th, 2013 2:16pm

I found my mistake.

With the option -d, i write : -d [DatabaseName], then it is sufficient to write: -d DatabaseName.

Thank for your help.

Simon

  • Marked as answer by Ste_62 Wednesday, December 18, 2013 1:15 PM
December 18th, 2013 4:15pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics