read MySQL db from pyodbc - pyodbc

I am trying to connect to a db in localhost, but it runs indefinitely.....
db_path=conn = pyodbc.connect(
r'DRIVER={SQL Server};'
r'SERVER=localhost;'
r'PORT=3306;'
r'DATABASE=mydb;'
r'UID=root;'
r'PWD=mypwd'
)
Can anyone help me please?

You are using a connection string for Microsoft SQL Server, and that won't work for MySQL. You should be using either
DRIVER={MySQL ODBC 5.3 Unicode Driver}
or
DRIVER={MySQL ODBC 5.3 ANSI Driver}
For more details on the other connection parameters that MySQL expects, look here

Related

Shiny App Connect dbPool through ODBC or specific driver

I'm struggling to connect my shiny application to one of the database we use in our company. I've succesfully connected to Azure / Mongo / SQL Server databases but now I've got a SAP SQL Anywhere 17 database to connect to.
Not surprisingly there's no specific connection to that database provided in the R Drivers (https://www.rstudio.com/products/drivers/).
Now I can solve this in two ways I believe, our IT department is convinced that a generic ODBC connection should work, or I have to get the specific SQL Anywhere drivers installed on my shiny app somehow.
For both solutions I can't find much online. If I search for generic ODBC connection the recommendations go to FreeTDS which is in the RODBC package, which then might not work together with Pool (according to what I've read).
Searching how to install specific drivers on a shiny application is also not bringing me much.
Try using
options(java.parameters="-Xmx8g")
library(RJDBC)
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver", "drivers/jdbc/mssql-jdbc-8.4.1.jre8.jar", identifier.quote="`")
processingStart = Sys.time()
conn <- dbConnect(drv,
"jdbc:sqlserver://SERVER_NAME;databaseName=DATABASE_NAME",
user = "USER_NAME",
"PASSWORD"
)

R to Oracle Connection Using ODBC

I am trying to make a connection from R to Oracle and I am having issues doing so.
Here is the connection script I am using with the DBI and odbc packages:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "Oracle in OraClient11g_home1",
Server = "orasade06.hc-sc.gc.ca",
SID = "sdv11040",
Schema = "STG",
Username = "username",
Password = "pw",
Port = 1521)
I am able to make a successful connection through Oracle SQL Developer to view my database and schema.
I have installed the Oracle ODBC driver (Oracle in OraClient11g_home1) on my machine, however I cannot make a successful connection from "R".
Here is the error I get:
Error: nanodbc/nanodbc.cpp:983: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Any help and guidance would be greatly appreciated.
Thanks.
I have written a tutorial around this, maybe take a look :
https://guillaumepressiat.github.io/blog/2019/11/oraclyr
Some key points :
If your Oracle client is 32-bit, using R 32-bit is a (or the) solution. Otherwise R and odbc error messages aren't crystal-clear
In RStudio see if an Oracle client appears in Connections Pane
It's easier on linux but strings and parameters for odbc are a little different.
Lastly, for connection string, this answer is interesting : how to make a connection string for oracle that includes hostname, instance name, user id, password using system.data.oracleclient?

Qt connecting to postgreSQL database without configuring ODBC

I'm trying to connect to a postgreSQL database without configuring System DSN with ODBC, I've googled a lot and I've tried a lot of connection strings but they didn't work, maybe I'm doing something wrong.
Here is one of the connection strings i've tried:
dbConnectionString = QString("Driver=PostgreSQLUnicode(x64)}|
Server="+DBhost+"|Port=%1|Database="+dbname+"|Uid="+username+"|Pwd="+password+"|ByteaAsLongVarBinary=1").arg(port)
db.setDatabaseName(dbConnectionString);
Any suggestion?

Connecting cassandra to Tableau Software

I want to connect Tableau software to my cassandra database. Note that i'm using tableau in windows7 and cassandra in ubuntu (Virtual machine).
For this i've installed the Cassandra ODBC (and Simba cassandra ODBC but i got the same problem). I got a connexion succes and i found my keyspace but not my tables !!!!!!
But no table in "cim" keyspace !!
Note that in my keyspace "cim" i have 3 tables that i can request with any problem in cassandra. Is there something i should do before creating the ODBC driver ???
Thank you for your help
The ODBC driver as it stands currently uses thrift so won't be able to communicate directly with cql3 to display the table names. Describe commands also won't work. However, you should still be able to select data from your tables. Updates to the ODBC driver should provide cql3 support at some point in the new year.
Update Simba ODBC driver for Cassandra supports CQL3 and solves your problem.
http://www.simba.com/connectors/apache-cassandra-odbc

Is it possible to programmatically get the server details from an ODBC DSN?

I'm working on some issues with psqlODBC's XA/MSDTC transaction handling and I find myself needing to obtain the server connection details (hostname, port, etc) from any user-supplied dsn programmatically without having psqlODBC invoked via the Driver Manager to do so.
Just parsed key/value string pairs will do; the problem is resolving user/system/file DSNs to get the underlying connection info.
The underlying issue I'm trying to solve is that a 32-bit application using MSDTC on a 64-bit system will supply a DSN that works for the 32-bit PostgreSQL driver. The 64-bit PostgreSQL drivers have different names - PostgresSQL ANSI vs PostgreSQL ANSI(x64) and similar for the Unicode drivers. So a DSN that works for a 32-bit app won't work for 64-bit apps ... like msdtc.exe. So I need a way to get the connection parameters the 32-bit app used and feed them into the 64-bit ODBC driver (or direct to libpq).
In the case of a DSN-less connection string like:
DRIVER={{PostgreSQL ANSI}};SERVER=127.0.0.1;PORT=5432;DATABASE=SOMEDB;UID=Administrator;PWD=;CA=disable"
I could just parse it to get the relevant info, but that won't work for file, system, or user DSNs where the XA transaction co-ordinator used by MSDTC only gets whatever the original user app passed to the ODBC layer - like:
DSN=SomeUserOrSystemDSNName
or
FILEDSN=C:\SomeFileDSN.dsn
and wrapped in that DSN is a DRIVER={{{PostgreSQL ANSI}}.
I've taken a look at the ODBC API docs and I don't see anything that seems to expose a way to load any DSN string, resolve file/system/user DSNs and get a parameter hash/map. OTOH, there's a lot of documentation out there, and some of the sections and function names aren't what I'd call predictable.
So - please tell me I'm missing something obvious, and there's a way to just:
GetDSNProperty("FILEDSN=C:\SomeFileDSN.dsn", "SERVER");
.. rather than writing hacky code to manually look up each DSN type.

Resources