Connect to sql external database

Hello everyone,
I’m trying to connect my anvil app to an external database using pyodbc

I installed the library but when I import it I’m getting this error:

ImportError: libodbc.so.2: cannot open shared object file: No such file or directory

It looks like libodbc.so.2 is missing on the server.
Did you experience the same error? Do you have any idea on how can I solve the problem?

Thanks

You need to add it yourself:

But libodbc.so.2 is not a python library if I understood correctly. Is it?

Ahh, I didn’t realize that, in that case you would want to use uplink:

Hi @MattDa,

At a guess, it looks like you’re using pyodbc, probably to connect to SQL Server. To do this, as well as just installing the pyodbc package, you also need to install the ODBC libraries in your server environment.

We’ve got beta functionality to support this - can you please drop us a line at support@anvil.works and we’ll switch this on for you?

You are right!
In any case, I managed to connect to the DB using pymssql.
What is, in your opinion, the best solution between pymssql and pyodbc?

Thanks!

Today as of right now, there is minimal difference.
People who like pymssql are going to continue using it, and people who have written code using pyodbc are not going to want to switch unless they have to.

In the past it was a FreeTDS drivers vs moving around “less free” drivers (and sometimes windows tokens) to your *nix machine for running the connection thing, since MsSQL is a microsoft product.
But that was years ago and pyodbc also uses FreeTDS now.

In the future:
pymssql - people doubt pymssql will get many updates as a project, but nobody is sure what that even means as it works fine
pydobc - Microsoft has said this is now their preferred way to connect python to MsSQL server and plan on supporting the pyodbc project as a contributor should it be necessary, but some people don’t care what Microsoft thinks/does.

The long and short of it is, if your are using one or the other and you run into an issue, like losing write access to a cursor because of credential issues, or very slow performance because your code wont stream data any other way than row by row, then switch to “the other one” and see if that helps.

Many thanks for the answer!