df.to_sql connection issue, any idea? - sql

Below are my codes
I want to export a python dataframe to azure SQL
df
Date ... Count
1 2019-09-04 ... 0
2 2019-09-04 ... 0
params = urllib.parse.quote_plus(r'Driver={ODBC Driver 13 for SQL Server};Server=tcp:xxxxxxx.database.windows.net,1433;Database=aaaaaaa;Uid=user#aaaaaaa;Pwd=$$$$$$$$$$$;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;')
conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params)
engine_azure = create_engine(conn_str,echo=True)
df.to_sql('users', con=engine)
Error below:
sqlalchemy.exc.InterfaceError: (pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
(Background on this error at: http://sqlalche.me/e/rvf5)

It sounds like that you want to save a pandas dataframe to Azure SQL Database via the function pandas.DataFrame.to_sql.
There is a SO thread Locating ODBC Driver 13.0 for SQL Server on Ubuntu Azure VM answered by me to show the connection code with SQLAlchemy and pyodbc. So I think your code is correct.
However, just according to your error information, it seems that you did not install Microsoft ODBC Driver for SQL Server first and just install the Python packages pyodbc and sqlalchemy. So please download the related odbc driver first from https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017 and install it. Then try your code again.
If you created your Azure SQL Database just now, I recommanded you need to install the 2017 version of MS ODBC driver and change the connection string with Driver={ODBC Driver 17 for SQL Server}( not 13 for 2013 driver version), because the MS 2013 ODBC driver not support the latest Azure Database.

Related

SSAS tabular project connection issue - memSQL DB as data source

I am trying to create a SSAS tabular project where data source is memSQL DB. I am able to connect to the memSQL database from any SQL client tool using MySQL and/or MariaDb OBDC driver. But when I am using the same ODBC driver for a SSAS tabular project "using OLEDB provider for ODBC" then I am getting error like below:
Failed to retrieve data from DATE_DIM. Reason: ERROR [42000] [MySQL][ODBC 5.3(w) Driver][mysqld-5.5.58]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*
FROM [DATE_DIM]' at line 1
ERROR [42000] [ma-3.0.9][5.5.58]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*
FROM [DATE_DIM]' at line 1
I have used the connect string as "Provider=MSDASQL.1;Persist Security Info=False;DSN=memSQLDB". Test connection was successful, but when trying to preview any table's data it throws the above error to me.
Is it a compatibility issue between memSQL (5.5.58) version and MySQL ODBC driver (version-5.3) or MariaDB OBDC driver (version-3.0.9)?
Can anyone suggest if there is any compatible ODBC driver exists, which can work with SSAS ?
With this error message, it appears it's less about authenticating correctly and more about the SSAS tool issuing queries with syntax MemSQL doesn't understand. Can you grab the query(ies) and post them here? That'll help us migrate these to compatible syntax. Depending on how the tool works, you may not have control over changing these queries, and will need the tool vendor to patch the query syntax to be more compatible.

How to resolve the following error in R using ODBC when connecting to SQL Server?

Error in result_fetch(res#ptr, n):
nanodbc/nanodbc.cpp:2966: 07009: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
I have cloned the code for an R dashboard from my company's datahub. When I run it, it has this error when it attempts to pull the data from our database. My partner has the exact same code on his machine and it runs just fine. I have read about similar errors and I only can find that it has to do with a bug in the SQL code. I don't think this can be the case because the code works as is on other machines.
maybe this similar question will help you
R DBI ODBC error: nanodbc/nanodbc.cpp:3110: 07009: [Microsoft][ODBC Driver 13 for SQL Server]Invalid Descriptor Index
If the code works on your coworkers computer, have you compared the EXACT R and Package versions as well as the SQL versions?

Excel-VBA to SQLite3 through ODBC Driver: primary database + attached database

I'm trying to connect from Excel-VBA to SQLite3 database through ODBC (Windows 10 x64).
I use Christian Werner's SQLite ODBC driver v 0.9999 (http://www.ch-werner.de/sqliteodbc) - as manual says I've installed both install both 32 and 64Bit versions of the driver.
Connecting to one database is ok:
ConnectionString = "DRIVER=SQLite3 ODBC Driver;Database=c:\first.db;"
Connecting to 2 databases (SQLite provides ability to connect to primary database + attached database) is also ok:
ConnectionString = "DRIVER=SQLite3 ODBC Driver;Database=c:\first.db;Attach=c:\second.db;"
but looks like VBA don't see tables from attached database - the following query fails:
SELECT * FROM [second].[table_name_in_second_db];
Does that SQLite ODBC driver supports attach database in connection string?
Or maybe I use incorrect syntax?
You don't handle attachments thru the connection. The primary database is handled in the connection properties. Once you have a valid connection you're essentially using sqlite engine. (the driver is a wrapper for sqlite.dll) Therefore you can attach databases as sql statements.
cn.execute "attach database 'C:\filename.db' as db"

VBSCRIPT connection to Oracle failing due to driver

I am using a vbscript which connects to SQL.
My connection String look like
connectionString = "DRIVER={Microsoft ODBC for Oracle};SERVER=convcsd;User Id=sysman;Password=csaadmin;"
Set connection = CreateObject("ADODB.Connection")
It is working on one server but not on another. it gives an error :
The oracle(tm) and networking components were not found. These
components are supplied by oracle corporation..
You will be unable to use this driver until these components have been
installed.
Please let me know how to add ODBC driver. I researched but not able to get through.
SQL Plus is an Oracle client yes but that is not enough to be able to use your script. You need an ODBC driver and prefable an OleDb driver (is faster) for Oracle on each pc you're going to use your script.
Compare the ODBC drivers between two 2 pc's with the Microsoft ODBC administrator (type ODBC in your startmenu searchwindow) and you will notice the difference. Use your Oracle installpackage and check the option to install the OleDb driver.
There is a Microsoft and an Oracle version, again it is best to use the Oracle driver. The connection string for Oracle OleDb is
Provider=OraOLEDB.Oracle;User ID=<user name>;Password=<password>;Data Source=<data source>

ODBC Linked server in sql 2005 doesn’t work from remote box

I have a dev workstation with sql 2005 installed and in it I created a linked server to a odbc connection to a clarion database. I can run select statements against it inside sql Mgt studio. When I take a second workstation and connect to the sql on the first box using sql mgt studio, then try the exact same query I get
OLE DB provider "MSDASQL" for linked server "liveclarion" returned message "[SoftVelocity Inc.][TopSpeed ODBC Driver][ISAM]ISAM Table Not Found".
Any thoughts? It appears to have the same functionality on a second sql server. No remote sql mgt studio connect success in queries against my linked ODBC clarion DB.
All done with windows authentication and the same AD user.
The error returned by the ODBC driver is "SAM table not found".
So I'm assuming you have a table called SAM - presumably in a table called Sam.Tps?
I'm wondering if you need to set a path to that file - ie if there's some difference in path or file name validity between your two tests. One assumes not, but I'd look in that direction first.