Database Error in Shiny

I dont know. Maybe restart your computer. I tried the athena one and it worked right away for me

There is no need to download the drivers locally, just change the driver in your dbConnect() code to something that is available at shinyapps.io before deploying your app. Which one to use depends on what SQL server you are trying to connect to, from your original post it seems you are trying to connect to a Microsoft SQL server so you could use the FreeTDS driver.

I installed some drivers that Shiny use but I can't connect to DB with these new drivers.

As I explained to you before, installing in your local system a bunch of drivers that you don't need is not going to help with this issue.
You must have in mind that when you deploy your app to shinyapps.io the app gets executed on their servers, not in your local machine, so it doesn't matter what you have installed in your local system.

If you want your app to be able to connect with the sql server from shinyapps.io then you have to use a connection like this, but have in mind that this is not going to work locally anymore

DBI::dbConnect(odbc::odbc(), Driver = "FreeTDS", 
    Database = "***", Server = "***", UID = "***", 
    PWD = "****", Port = 1433)
1 Like

See the section of the documentation on using the config package to handle differences between connecting locally versus shinyapps.io.

Locally, use whatever driver name you have installed. On shinyapps.io, use the professional driver or FreeTDS driver.

1 Like

I connected to DB with FreeTDS.

DBI::dbConnect(odbc::odbc(), Driver = "FreeTDS", 
    Database = "***", Server = "***", UID = "***", 
    PWD = "****", Port = 1433)

I wrote this code to ShinyApp but I got this error:

Hi,

I used FreeTDS but I got the error, as I mentioned to @andresrcs

I hold DB connection info at "con" object.

config::get("con")
Error in config::get("con") : 
  Config file config.yml not found in current working directory or parent directories

How can I use config function in my situation?

That config.yml error message looks like you did not create a file called config.yml as this doc describes.

I would recommend reading that doc thoroughly. Ultimately it's not clear to me from this thread what database you are trying to connect to. SQL Server? It also is not clear whether the database is "world accessible" and will be accessible from Shinyapps.io.

Remember that shinyapps.io is running your code somewhere else entirely. Are you a part of an organization? Is your database accessible publicly to anyone on the internet? At a minimum, it needs to allow traffic from shinyapps.io's IP addresses, as discussed here:

https://docs.rstudio.com/shinyapps.io/applications.html#firewalls

Otherwise no amount of work with the drivers is going to work, because the networking traffic will never reach the database.

Actually, I see in your original post that your port is 1433. That looks to be the default port for SQL Server.

If that is the database you are using, I wonder whether using SQLServer as your driver is a better bet than FreeTDS. If so, you will probably need to change your connection parameters to match the driver documentation:

You will probably want to use a "DSN-less" connection string, which is described on page 37.

The other questions I asked should still be addressed, please, as they would potentially prohibit any of this from working.

A post was split to a new topic: Problem connecting to database

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.