SQL Server BCP在vb6内执行

发布于 2024-12-26 10:17:26 字数 259 浏览 5 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨轻弹 2025-01-02 10:17:27

几十年前(天哪),我编写了一个 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.

一个人练习一个人 2025-01-02 10:17:27

我很想知道 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 ...

羁拥 2025-01-02 10:17:26

人们普遍对 BCP 存在误解。 BCP 是可执行文件。 BCP 不是 SQL 命令。您在 Internet 上看到了大量有关如何从 SQL 语句或存储过程执行 BCP 的详细信息。通常的答案涉及使用存储过程 XP_CMDSHELL 来运行 BCP 可执行文件。为了使该解决方案发挥作用,需要对 SQL Server 配置进行一些调整。

由于您是从 VB 应用程序中运行 BCP,因此您可以运行 BCP 可执行文件,而无需从应用程序预先存在到数据库服务器的连接。要运行的命令行语句类似于:

 bcp.exe "SELECT * FROM TABLE" QUERYOUT C:\FILE.TXT -c -t -T -SmyServer -UtheUsername -PthePassword

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:

 bcp.exe "SELECT * FROM TABLE" QUERYOUT C:\FILE.TXT -c -t -T -SmyServer -UtheUsername -PthePassword
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文