2
$ freebcp DWSTAGE.BCPTEST in bcptest.txt -f cdr.fmt -S serverfromfreetds -U user@azureserver -P password
Msg 208, Level 16, State 1
Server 'azureserver', Line 1
    Invalid object name 'DWSTAGE.BCPTEST'.
Msg 208, Level 16
General SQL Server error: Check messages from the SQL Server

Msg 20064, Level 2
Attempt to use Bulk Copy with a non-existent Server table

$ freebcp DATABASENAME.DWSTAGE.BCPTEST in bcptest.txt -f cdr.fmt -S serverfromfreetds -U user@azureserver -P password
Msg 40515, Level 15, State 1
Server 'azureserver', Line 16
    Reference to database and/or server name in 'DATABASENAME.DWSTAGE.BCPTEST' is not supported in this version of SQL Server.
Msg 40515, Level 15
General SQL Server error: Check messages from the SQL Server

Msg 20064, Level 2
Attempt to use Bulk Copy with a non-existent Server table

我还尝试使用 -D 选项将数据库添加到命令行。该连接的默认数据库设置为 freetds.conf 中唯一的 Azure 数据库。

否则,与 SQL Azure 的连接似乎很好——我只是无法让 FreeBCP 工作:

$ isql serverfromfreetds user@azuredatabasename password
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> SELECT COUNT(*) FROM DWSTAGE.BCPTEST;
+------------+
|            |
+------------+
| 0          |
+------------+
SQLRowCount returns 1
1 rows fetched
SQL> SELECT COUNT(*) FROM DWSTAGE.BCPTESTX;
[ISQL]ERROR: Could not SQLExecute
SQL> 

这似乎是一些数据库/架构混乱,但我找不到有效的设置组合。

4

2 回答 2

2

From the FreeTDS mailing list:

The message 208 comes from the server. A quick look at freebcp.c shows argv[1] isn't parsed. It's copied to a struct and used verbatim e.g.

                    if (dbfcmd(dbproc, "SET FMTONLY ON select *

from %s SET FMTONLY OFF", pdata->dbobject) == FAIL)

My guess is that the account you're logging in with has a default database, and that database is not the one containing DWSTAGE.BCPTEST. The Azure server rejects dbname.schema.object syntax, and freebcp has no -D option because until Azure every TDS server did accept that syntax.

You could verify that using

    $ freebcp 'select db_name()' queryout /dev/stdout ...

As a temporary workaround, I think this would work:

    freebcp DWSTAGE.BCPTEST in bcptest.txt \
    -O 'USE dbname' \
    -f cdr.fmt -S serverfromfreetds -U user@azureserver -P password

A permanent fix would support -D.


Yes, that user's default database is probably master. There IS a default database set up in the odbc config, but I was mistaken, there is no such option in the freeetds.conf.

We've moved away from trying to get Linux to work for this process for now, but I'll revisit this.

I expect that workaround will not work because USE isn't supported - you do in fact have to connect directly to the database, because of the nature of the SQL Azure architecture.


Yes, you're right. I forgot about that.

About a year ago we added the DBSETLDBNAME macro as a way to set the dbname in the db-lib LOGINREC. That sets the dbname in the login packet, obviating the need for "USE dbname". freebcp could be modified to support that feature with a -D option.


See change

http://gitorious.org/freetds/freetds/commit/4a21ded022405693607e71938d0c6173816f5ff9/diffs/c34afafd2fec4cbba9b245e4f13a5471c6fb8041

(add support for -D in freebcp)

于 2012-11-21T04:07:55.717 回答
0

我已经freebcp开始使用 Ubuntu 12.04 和 Azure SQL。它遵循上面提到支持的答案-D

首先,我freetds按照此线程中的说明安装和配置:https ://askubuntu.com/questions/167491/connecting-ms-sql-using-freetds-and-unixodbc-isql-no-default-driver-specified

基本上,这包括: sudo apt-get install tdsodbc unixodbc freetds-bin

这把我带到了这个线程开始的地方;freebcp可以连接,但我收到有关“引用数据库...此版本的 SQL 服务器不支持”的错误。

下一步要注意freebcpapt-get 安装的版本是相当旧的版本。而是从ftp://ftp.freetds.org/pub/freetds/stable/下载更新的版本。我用过freetds-1.00.9.tar.gz

使用安装它./configuremake然后使用这个新freebcp的,但使用-D.

这是我的命令字符串:freetds-1.00/src/apps/freebcp bcptest in bcptest.big.dat -U myUserName@myServer -S MyServerConfig -P 'mypa$$word' -D myDatabase -c -e upload.err

于 2017-01-18T17:56:10.883 回答