SQL Server 的 DBI 一般网络错误 - nanodbc/nanodbc.cpp:2695

问题描述

我正在尝试通过 DBI 包连接到 Microsoft sql Server。 该表有 1700 万行。

我正在使用 DBI 包,我尝试了两种方法

    # libraries
    library("DBI")
    library("tidyverse")
    library("tictoc")
    library("dplyr")
    library("dbplyr")
    
    # open connection to MS sql server
    consql <- DBI::dbConnect(odbc::odbc(),database = 'database',SERVER_NAME_sql,uid = userIdsql,pwd = passwordsql)
                             
    # --------------------------------
    # 1st way - dbGetQuery
    # --------------------------------
    
    # extract all rows
    mp_jobOrdersItems_17mil <- dbGetQuery(consql,"select * from dbo.table_17ml")        %>%
      as_tibble
    
    # --------------------------------  
    # 2ndway - dbSendQuery and multiple dbFetch
    # --------------------------------
    
    # Fetch in chunks
    rs <- dbSendQuery(consql,"select * from dbo.table_17ml")
    
    # loop
    while (!dbHasCompleted(rs)) {
        chunk <- dbFetch(rs,1000)
        print(nrow(chunk))
    }
    
    # clear results
    dbClearResult(rs)
    
    
    # close Connection
    DBI::dbdisconnect(consql)

总结:

  • 使用 r dbGetQuery() 我只能下载少于 10 万行
  • 使用 r dbSendQuery()r dbFetch(),我尝试了一次或多次获取,我只能下载不到 20 万行
  • 如果我尝试使用所有表格行,我会收到以下错误

我收到错误

result_fetch(res@ptr,n) 中的错误:nanodbc/nanodbc.cpp:2695: HY018: [Microsoft][ODBC sql Server 驱动程序][dbnETLIB]ConnectionWrite (发送())。 [Microsoft][ODBC sql Server 驱动程序][dbnETLIB]一般 网络错误。检查您的网络文档。

我测试没有问题:

  • 连接
  • 我看到了带有 Rstudio 连接接口的表格
  • 我可以读取一个小样本并在 data.frame 或 tibble 中接收 R

谁能帮助我或给我一些建议?

提前致谢

MC

环境信息:

R 信息

R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  Grdevices utils     datasets  methods   base     

other attached packages:
 [1] dbplyr_2.1.0    tictoc_1.0      forcats_0.5.1   stringr_1.4.0   dplyr_1.0.5     purrr_0.3.4     readr_1.4.0     tidyr_1.1.3    
 [9] tibble_3.1.0    ggplot2_3.3.3   tidyverse_1.3.0 DBI_1.1.1      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6       cellranger_1.1.0 pillar_1.5.1     compiler_4.0.4   tools_4.0.4      odbc_1.3.1       bit_4.0.4        lubridate_1.7.10
 [9] jsonlite_1.7.2   lifecycle_1.0.0  gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.10     reprex_1.0.0     cli_2.3.1        rstudioapi_0.13 
[17] haven_2.3.1      withr_2.4.1      xml2_1.3.2       httr_1.4.2       fs_1.5.0         generics_0.1.0   vctrs_0.3.6      hms_1.0.0       
[25] bit64_4.0.5      grid_4.0.4       tidyselect_1.1.0 glue_1.4.2       R6_2.5.0         fansi_0.4.2      readxl_1.3.1     modelr_0.1.8    
[33] blob_1.2.1       magrittr_2.0.1   backports_1.2.1  scales_1.1.1     ellipsis_0.3.1   rvest_1.0.0      assertthat_0.2.1 colorspace_2.0-0
[41] utf8_1.2.1       stringi_1.5.3    munsell_0.5.0    broom_0.7.5      Crayon_1.4.1

sql 服务器信息

Microsoft sql Azure (RTM) - 12.0.2000.8   Feb  4 2021 02:12:36   copyright (C) 2019 Microsoft Corporation 

odbc 列表

                                name        attribute value
1                         sql Server         APILevel     2
2                         sql Server ConnectFunctions   YYY
3                         sql Server        CPTimeout    60
4                         sql Server    DriverODBCVer 03.50
5                         sql Server        FileUsage     0
6                         sql Server         sqlLevel     1
7                         sql Server       UsageCount     1
8      sql Server Native Client 11.0       UsageCount     1
9      sql Server Native Client 11.0         APILevel     2
10     sql Server Native Client 11.0 ConnectFunctions   YYY
11     sql Server Native Client 11.0        CPTimeout    60
12     sql Server Native Client 11.0    DriverODBCVer 03.80
13     sql Server Native Client 11.0        FileUsage     0
14     sql Server Native Client 11.0         sqlLevel     1
15     ODBC Driver 17 for sql Server       UsageCount     1
16     ODBC Driver 17 for sql Server         APILevel     2
17     ODBC Driver 17 for sql Server ConnectFunctions   YYY
18     ODBC Driver 17 for sql Server        CPTimeout    60
19     ODBC Driver 17 for sql Server    DriverODBCVer 03.80
20     ODBC Driver 17 for sql Server        FileUsage     0
21     ODBC Driver 17 for sql Server         sqlLevel     1
22    MongoDB ODBC 1.4.2 ANSI Driver       UsageCount     1
23 MongoDB ODBC 1.4.2 Unicode Driver       UsageCount     1

更新:2021 年 4 月 1 日

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...