1
   library(RMySQL)
    connectDB <- function(dbName, hostname, username)
   {
  sqlConnection <- NULL
 result = tryCatch({
 sqlConnection <- dbConnect(MySQL(), dbname=dbName, host = hostname, user= username, 
  password=.rs.askForPassword("Enter password: ") )

 },

 warning = function(w){
  print("warning")
  supresswarning()
},

 error = function(e){
  print(paste("Error : ", e))

},

 finally = {
  print("connected")

 })

 return (sqlConnection)   

}

 #Creating Connection to database

con <- connectDB("data_analytics", "localhost", "root")

This is the code I am trying to run in Rstudio. On running this line

con <- connectDB("data_analytics", "localhost", "root")"

it shows error

Error :  Error in 
.rs.askForPassword(\"Enter password: \"): could not find function \".rs.askForPassword\"\n

please help me to solve it. Thanks

Phil
  • 7,287
  • 3
  • 36
  • 66
  • You are calling a function for the password argument (`.rs.askForPassword`) that does not exist. – Phil May 03 '21 at 14:30
  • how can I solve it? @Phil – Mayank Gupta May 03 '21 at 15:09
  • By not calling something that doesn't exist. Looking at the documentation, the password argument is expecting a string, something like `dbConnect(..., password = "mypassword", ...)` – Phil May 03 '21 at 15:13
  • just did what you said @Phil ....now i am getting this : "Error : Error in .local(drv, ...): Failed to connect to database: Error: Plugin caching_sha2_password could not be loaded: The specified module could not be found. Library path is '/mingw32/lib/mariadb/plugin/caching_sha2_password.dll'\n\n" – Mayank Gupta May 03 '21 at 15:32
  • I'm not able to help further, but looking around you may have the same issue as here https://stackoverflow.com/questions/54099722/how-to-connect-r-to-mysql-failed-to-connect-to-database-error-plugin-caching/54101124 – Phil May 03 '21 at 16:07
  • Thanks for giving your valuable time @Phil...have a nice day – Mayank Gupta May 03 '21 at 16:25
  • I'd suggest the use of `keyring` or `config` packages for the handling of "secrets" like db passwords. – r2evans May 08 '21 at 19:51

0 Answers0