Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: invalid names for slots of class “Microsoft SQL Server”: ptr, quote, info, encoding #558

Closed
skanskan opened this issue Apr 6, 2023 · 3 comments · Fixed by #668
Labels
bug an unexpected problem or unintended behavior mssql Microsoft SQL Server
Milestone

Comments

@skanskan
Copy link

skanskan commented Apr 6, 2023

Hello.

I'm trying to run this repository
https://github.com/oxford-pharmacoepi/Studyathon_LCPASC

And I have problems when trying to create a connection to a SQL Server with DBI and odbc.

library(DBI)
library(odbc)
DBI::dbConnect(odbc(),
+                       Driver = 'sql server',
+                       Server = 'myserver',
+                       UID = 'myuser',
+                       PWD = 'mypassword,
+                       Port = myport
+  )

I have also tried with 'dsn' and 'user' = instead of Server and UID.
And with different values for Driver, such as 'SQL Server', 'ODBC Driver 17 for SQL Server', 'SQL Server Native Client 11.0', 'sqlserver'...

But it keeps producing this error:

Found more than one class "Microsoft SQL Server" in cache; using the first, from namespace 'DatabaseConnector'
Also defined by ‘.GlobalEnv’
Error in initialize(value, ...) : 
  invalid names for slots of class “Microsoft SQL Server”: ptr, quote, info, encoding

I have tried reinstalling odbc and DBI from cran and also from github, with no luck.

Database in the server

SQL Server 2017 v14.0

Drivers installed on my local computer

ODBC Driver 17 for SQL Server
SQL Server 10.0
SQL Server Native Client 11

Session Info
devtools::session_info()

R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252    LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Spain.1252    
system code page: 65001

- Session info --------------------------------------------------------------------------------------------------------------------------
 setting  value
 version  R version 4.1.2 (2021-11-01)
 os       Windows 10 x64 (build 18363)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  Spanish_Spain.1252
 ctype    Spanish_Spain.1252
 tz       Europe/Paris
 date     2023-04-06
 rstudio  2021.09.2+382 Ghost Orchid (desktop)
 pandoc   NA

- Packages ------------------------------------------------------------------------------------------------------------------------------
 ! package             * version date (UTC) lib source
   backports             1.4.1   2021-12-13 [1] CRAN (R 4.1.2)
   bit                   4.0.5   2022-11-15 [1] CRAN (R 4.1.3)
   bit64                 4.0.5   2020-08-30 [1] CRAN (R 4.1.3)
   blob                  1.2.4   2023-03-17 [1] CRAN (R 4.1.3)
   brio                  1.1.3   2021-11-30 [1] CRAN (R 4.1.3)
   cachem                1.0.7   2023-02-24 [1] CRAN (R 4.1.3)
   callr                 3.7.3   2022-11-02 [1] CRAN (R 4.1.3)
   CDMConnector        * 0.5.1   2023-03-22 [1] CRAN (R 4.1.3)
   checkmate             2.1.0   2022-04-21 [1] CRAN (R 4.1.3)
   chromote              0.1.1   2022-09-07 [1] CRAN (R 4.1.3)
   CirceR              * 1.3.0   2023-04-06 [1] Github (OHDSI/CirceR@f5a0824)
   cli                   3.6.1   2023-03-23 [1] CRAN (R 4.1.3)
 P codetools             0.2-18  2020-11-04 [?] CRAN (R 4.1.2)
   colorspace            2.1-0   2023-01-23 [1] CRAN (R 4.1.3)
   crayon                1.5.2   2022-09-29 [1] CRAN (R 4.1.3)
   curl                  5.0.0   2023-01-12 [1] CRAN (R 4.1.3)
   data.table            1.14.8  2023-02-17 [1] CRAN (R 4.1.3)
   DatabaseConnector   * 6.1.0   2023-03-15 [1] CRAN (R 4.1.3)
   DBI                 * 1.1.3   2022-06-18 [1] CRAN (R 4.1.3)
   dbplyr              * 2.3.2   2023-03-21 [1] CRAN (R 4.1.3)
   desc                  1.4.2   2022-09-08 [1] CRAN (R 4.1.3)
   devtools              2.4.5   2022-10-11 [1] CRAN (R 4.1.3)
   digest                0.6.31  2022-12-11 [1] CRAN (R 4.1.3)
   dplyr               * 1.1.1   2023-03-22 [1] CRAN (R 4.1.3)
   ellipsis              0.3.2   2021-04-29 [1] CRAN (R 4.1.3)
   fansi                 1.0.4   2023-01-22 [1] CRAN (R 4.1.3)
   fastmap               1.1.1   2023-02-24 [1] CRAN (R 4.1.3)
   fs                    1.5.2   2021-12-08 [1] CRAN (R 4.1.3)
   generics              0.1.3   2022-07-05 [1] CRAN (R 4.1.3)
   ggplot2             * 3.4.2   2023-04-03 [1] CRAN (R 4.1.2)
   glue                  1.6.2   2022-02-24 [1] CRAN (R 4.1.3)
   googleVis             0.7.1   2023-03-01 [1] CRAN (R 4.1.3)
   gtable                0.3.3   2023-03-21 [1] CRAN (R 4.1.3)
   here                * 1.0.1   2020-12-13 [1] CRAN (R 4.1.3)
   hms                   1.1.3   2023-03-21 [1] CRAN (R 4.1.3)
   htmltools             0.5.5   2023-03-23 [1] CRAN (R 4.1.3)
   htmlwidgets           1.6.2   2023-03-17 [1] CRAN (R 4.1.3)
   httpuv                1.6.9   2023-02-14 [1] CRAN (R 4.1.3)
   igraph              * 1.4.1   2023-02-24 [1] CRAN (R 4.1.3)
   IncidencePrevalence * 0.2.0   2023-03-27 [1] CRAN (R 4.1.3)
   jsonlite              1.8.4   2022-12-06 [1] CRAN (R 4.1.3)
   later                 1.3.0   2021-08-18 [1] CRAN (R 4.1.3)
 P lattice               0.20-45 2021-09-22 [?] CRAN (R 4.1.2)
   lifecycle             1.0.3   2022-10-07 [1] CRAN (R 4.1.3)
   log4r               * 0.4.3   2022-11-28 [1] CRAN (R 4.1.3)
   lubridate           * 1.9.2   2023-02-10 [1] CRAN (R 4.1.3)
   magrittr              2.0.3   2022-03-30 [1] CRAN (R 4.1.3)
 P MASS                * 7.3-54  2021-05-03 [?] CRAN (R 4.1.2)
   MatchIt             * 4.5.2   2023-03-22 [1] CRAN (R 4.1.3)
   memoise               2.0.1   2021-11-26 [1] CRAN (R 4.1.3)
   mime                  0.12    2021-09-28 [1] CRAN (R 4.1.1)
   miniUI                0.1.1.1 2018-05-18 [1] CRAN (R 4.1.3)
   mnormt                2.1.1   2022-09-26 [1] CRAN (R 4.1.3)
   munsell               0.5.0   2018-06-12 [1] CRAN (R 4.1.3)
 P nlme                  3.1-153 2021-09-07 [?] CRAN (R 4.1.2)
 D odbc                * 1.3.4   2023-01-17 [1] CRAN (R 4.1.3)
   OhdsiSharing          0.2.2   2023-04-06 [1] Github (OHDSI/OhdsiSharing@df03233)
   ParallelLogger        3.1.0   2022-12-08 [1] CRAN (R 4.1.3)
   pillar                1.9.0   2023-03-22 [1] CRAN (R 4.1.3)
   pkgbuild              1.4.0   2022-11-27 [1] CRAN (R 4.1.3)
   pkgconfig             2.0.3   2019-09-22 [1] CRAN (R 4.1.3)
   pkgload               1.3.2   2022-11-16 [1] CRAN (R 4.1.3)
   plyr                  1.8.8   2022-11-11 [1] CRAN (R 4.1.3)
   poLCA               * 1.6.0.1 2022-04-25 [1] CRAN (R 4.1.3)
   prettyunits           1.1.1   2020-01-24 [1] CRAN (R 4.1.3)
   processx              3.8.0   2022-10-26 [1] CRAN (R 4.1.3)
   profvis               0.3.7   2020-11-02 [1] CRAN (R 4.1.3)
   promises              1.2.0.1 2021-02-11 [1] CRAN (R 4.1.3)
   ps                    1.7.4   2023-04-02 [1] CRAN (R 4.1.3)
   psych               * 2.3.3   2023-03-18 [1] CRAN (R 4.1.3)
   purrr               * 1.0.1   2023-01-10 [1] CRAN (R 4.1.3)
   R6                    2.5.1   2021-08-19 [1] CRAN (R 4.1.3)
   Rcpp                  1.0.10  2023-01-22 [1] CRAN (R 4.1.3)
   readr               * 2.1.4   2023-02-10 [1] CRAN (R 4.1.3)
   remotes               2.4.2   2021-11-30 [1] CRAN (R 4.1.3)
   renv                  0.17.2  2023-03-17 [1] CRAN (R 4.1.3)
   reshape2            * 1.4.4   2020-04-09 [1] CRAN (R 4.1.3)
 D rJava                 1.0-6   2021-12-10 [1] CRAN (R 4.1.2)
   rjson                 0.2.21  2022-01-09 [1] CRAN (R 4.1.2)
   rlang                 1.1.0   2023-03-14 [1] CRAN (R 4.1.3)
   RODBC               * 1.3-20  2022-12-06 [1] CRAN (R 4.1.3)
   RPostgres           * 1.4.5   2023-01-20 [1] CRAN (R 4.1.3)
   rprojroot             2.0.3   2022-04-02 [1] CRAN (R 4.1.3)
   rstudioapi            0.14    2022-08-22 [1] CRAN (R 4.1.3)
   scales                1.2.1   2022-08-20 [1] CRAN (R 4.1.3)
   scatterplot3d       * 0.3-43  2023-03-14 [1] CRAN (R 4.1.3)
   sessioninfo           1.2.2   2021-12-06 [1] CRAN (R 4.1.3)
   shiny                 1.7.4   2022-12-15 [1] CRAN (R 4.1.3)
   SqlRender             1.13.1  2023-03-21 [1] CRAN (R 4.1.3)
   stringi               1.7.12  2023-01-11 [1] CRAN (R 4.1.3)
   stringr               1.5.0   2022-12-02 [1] CRAN (R 4.1.3)
   testthat            * 3.1.7   2023-03-12 [1] CRAN (R 4.1.3)
   tibble              * 3.2.1   2023-03-20 [1] CRAN (R 4.1.3)
   tidyr                 1.3.0   2023-01-24 [1] CRAN (R 4.1.3)
   tidyselect            1.2.0   2022-10-10 [1] CRAN (R 4.1.3)
   timechange            0.2.0   2023-01-11 [1] CRAN (R 4.1.3)
   Trajectories        * 1.0.0   2023-04-06 [1] Github (EHDEN/Trajectories@8a18c78)
 R TreatmentPatterns   * 2.0.0   <NA>       [?] <NA>
   tzdb                  0.3.0   2022-03-28 [1] CRAN (R 4.1.3)
   urlchecker            1.0.1   2021-11-30 [1] CRAN (R 4.1.3)
   usethis               2.1.6   2022-05-25 [1] CRAN (R 4.1.3)
   utf8                  1.2.3   2023-01-31 [1] CRAN (R 4.1.3)
   vctrs                 0.6.1   2023-03-22 [1] CRAN (R 4.1.3)
   webshot2              0.1.0   2022-05-18 [1] CRAN (R 4.1.3)
   websocket             1.4.1   2021-08-18 [1] CRAN (R 4.1.3)
   withr                 2.5.0   2022-03-03 [1] CRAN (R 4.1.3)
   xtable                1.8-4   2019-04-21 [1] CRAN (R 4.1.3)
   zip                 * 2.2.2   2022-10-26 [1] CRAN (R 4.1.3)

The SQL Server works well and it's accessible with other libraries such as RODBC, but with odbc produces an error.

I can't upgrade R nor install some programs because I don't have administrator rights.

@skanskan
Copy link
Author

skanskan commented Apr 18, 2023

Any solution?
I have also tried with the latest ODBC 18 Windows drivers and with the latest DBI and odbc R libraries, but I'm still getting the same error.

@skanskan
Copy link
Author

skanskan commented Apr 23, 2023

Using
unloadNamespace("DatabaseConnector")
allows me to create the connection with dbConnect.
but after that sometimes I get errors like
Not a validObject(): no slot of name "name" for this object of class "Microsoft SQL Server"

@hadley hadley added bug an unexpected problem or unintended behavior mssql Microsoft SQL Server labels Apr 24, 2023
@hadley hadley added this to the v1.4.0 milestone Apr 24, 2023
@hadley
Copy link
Member

hadley commented Dec 12, 2023

Looking into this in a bit more detail, I think this is most likely a problem with DatabaseConnector, since it's copying code from odbc: https://github.com/OHDSI/DatabaseConnector/blob/bee58a314996123b59e08bd489bf712e14391c4f/R/DBI.R#L61-L70. I think we need to export these classes so that DatabaseConnector can import them.

hadley added a commit that referenced this issue Dec 12, 2023
This makes it possible for other packages to import them, without creating clashing definitions. Fixes #558.
hadley added a commit that referenced this issue Dec 12, 2023
This makes it possible for other packages to import them, without creating clashing definitions. Fixes #558.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior mssql Microsoft SQL Server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants