简体   繁体   English

AZUR-使用带有查询的BCP导出

[英]AZUR - Export Using BCP with Query

I want to export data from a database Azur to an Excel file. 我想将数据从数据库Azur导出到Excel文件。 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 bcp [数据库名称]。[表] 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 : 但是,当我想对命令中的SQL Query执行相同的操作时,如下所示:

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 bcp“从[dbo]。[ForecastTrialDisag]中选择field1,Field2” 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. SQLState = 37000,NativeError = 4060错误= [Microsoft] [SQL Server Native Client 10.0] [SQL Server]无法打开登录请求的数据库“ [DataBaseName]”。 The login failed. 登录失败。

SQLState = 28000, NativeError = 18456 Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'UserName'. SQLState = 28000,NativeError = 18456错误=用户'UserName'的[Microsoft] [SQL Server Native Client 10.0] [SQL Server]登录失败。

I don't understand why it doesn't work with a SQL query. 我不明白为什么它不适用于SQL查询。 UserName, databaseName and password are OK. 用户名,数据库名和密码都可以。

Thank you for your help, 谢谢您的帮助,

Simon 西蒙

I believe the username is in the format of: "user@server" without the "databases.windows.net" part at the end. 我相信用户名的格式为:“ user @ server”,末尾没有“ databases.windows.net”部分。

Have you tried that? 你尝试过吗?

If the password is a strong one - contains punctuation for example, in my case I had a * and and ^ character in the password - than the use of double quotes for the password is needed: 如果密码是一个强密码(例如包含标点符号),那么在我的情况下,密码中带有*和^字符,则需要在密码中使用双引号:

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" bcp“从[dbo]。[ForecastTrialDisag]中选择field1,Field2” QUERYOUT C:.. \\ Test_Export.xls -d [DataBaseName] -c -U UserName@ServerName.database.windows.net -S tcp:ServerName.database。 Windows.net -P“ xxxxxx”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM