SQL Server BCP在vb6内执行
我想在 VB6 应用程序中执行 BCP 命令,我该怎么做?
我尝试了这段代码:
BCPCMD = " 'BCP ""SELECT * FROM TABLE"" QUERYOUT C:\FILE.TXT -c -t -T -S MYSERVER' "
sql = "EXEC MASTER..XP_CMDSHELL " & BCPCMD
db.Execute (sql)
代码执行没有错误,但不生成任何文件:/
I want to execute a BCP command in a VB6 application, how can i do it?
I tried this code:
BCPCMD = " 'BCP ""SELECT * FROM TABLE"" QUERYOUT C:\FILE.TXT -c -t -T -S MYSERVER' "
sql = "EXEC MASTER..XP_CMDSHELL " & BCPCMD
db.Execute (sql)
The code execute with no errors, but dont generate any file :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
几十年前(天哪),我编写了一个 VB6(或者当时可能是 VB5)包装器,用于从 Visual Basic 处理 BCP。我用了很多年了。
享受。
Decades ago (sweet lord), I wrote a VB6 (or maybe VB5 at the time) wrapper for handling BCP from Visual Basic. I used it for years.
Enjoy.
我很想知道 BCP 是否可以在 Management studio 中使用?据我所知,这是一个命令提示符实用程序......
I'm eager to know whether BCP can be used in Management studio ?? As far as i know it's a command prompt utility ...
人们普遍对 BCP 存在误解。 BCP 是可执行文件。 BCP 不是 SQL 命令。您在 Internet 上看到了大量有关如何从 SQL 语句或存储过程执行 BCP 的详细信息。通常的答案涉及使用存储过程 XP_CMDSHELL 来运行 BCP 可执行文件。为了使该解决方案发挥作用,需要对 SQL Server 配置进行一些调整。
由于您是从 VB 应用程序中运行 BCP,因此您可以运行 BCP 可执行文件,而无需从应用程序预先存在到数据库服务器的连接。要运行的命令行语句类似于:
There's a general misconception out there about BCP. BCP is an executable. BCP is not a SQL command. You see a lot of information on the internet with details on how to execute BCP from a SQL statement or stored procedure. The usual answer involves using the stored proc XP_CMDSHELL to run the BCP executable. For this solution to work some adjustments need to be made to the SQL Server configuration.
Since you are running BCP from within a VB application you can run the BCP executable without having a pre-existing connection to the database server from your application. The command line statement to run looks something like: