I am using a Windows 10 machine trying to connect to an SQL Serve (SQL Developer 2017) using Python. My code is as follows:
from sqlalchemy import create_engine
engine = create_engine('mssql+pymssql://Sonwabo:helpdeskNo1#localhost:1433/dbname')
connect = engine.connect()
I get the following error:
pymssql.OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost:1433)\nNet-Lib error during Unknown error (10060)\n')
I remember my sqlalchemy connection being very finicky when connecting to SQL Server too. I had to do some experimenting with drivers and switching between pymssql and pyodbc. This is what ended up working for me.
server = 'server'
username = 'user'
password = 'pass'
driver = 'ODBC+DRIVER+17+for+SQL+Server'
engine_stmt = 'mssql+pyodbc://{}:{}#{}/{}?driver={}'.format(username,
password,
server,
database,
driver)
engine = sqlalchemy.create_engine(engine_stmt)
I think you should follow as the format below.
server = ‘ServerAddress'
database = 'DataBaseName'
username = 'UserName'
password = 'Password'
driver = 'SQL Server Native Client 11.0'
DataBase_connection = f'mssql://{username}:{password}#{server}/{database}?driver={driver}'
engine = create_engine(DataBase_connection)
connection = engine.connect()
Related
I am trying this code to connect to the MariaDB in the Red Hat Linux remote server in R.
con <- DBI::dbConnect(odbc::odbc(),
driver = ????? ,
database = "test_db",
UID = rstudioapi::askForPassword("Database user"),
PWD = rstudioapi::askForPassword("Database password"),
host = "xxx.xx.xx",
port = ????? )
Does this above function help connect to the MariaDB in the remote server?
I am not aware of what goes under the driver argument in the above function in case of MariaDB.
Also How can I find the port number for the remote server I am using?
Please help me with this. Thanks.
I have an Amazon linux instance on which i have installed a server named ejabberd
Inside it I have a code written in erlang as (db.erl).
-module(db).
-export([connection/0]).
connection()->
odbc:start(),
ConnectionString = "DSN=qaz;UID=root;PWD=abc",
{ok, Ref} = odbc:connect(ConnectionString, []),
Ref.
But when I this code is about to run I get an error as
[error] gen_server myapp terminated with reason: no match of right hand
value {error,"[unixODBC][Driver Manager]Can't open lib
'/usr/lib/libmyodbc5.so' : file not found SQLSTATE IS: 01000 Connection to
database failed."} in db:connection/0 line 15
10:34:15.111 [error] CRASH REPORT Process myapp with 0 neighbours exited
with reason: no match of right hand value {error,"[unixODBC][Driver
Manager]Can't open lib '/usr/lib/libmyodbc5.so' : file not found SQLSTATE
IS: 01000 Connection to database failed."} in db:connection/0 line 15 in
gen_server:terminate/7 line 812
10:34:15.111 [error] Supervisor frequency_sup had child myapp started with
myapp:start() at <0.502.0> exit with reason no match of right hand value
{error,"[unixODBC][Driver Manager]Can't open lib '/usr/lib/libmyodbc5.so' :
file not found SQLSTATE IS: 01000 Connection to database failed."} in
db:connection/0 line 15 in context child_terminated
I have edited my /etc/odbc.ini and /root/.odbc.ini with following configurations
[ODBC Data Sources]
qaz= ODBC for MySQL
[qaz]
Driver = /usr/lib64/libmyodbc5.so
Description = ODBC for MySQL
SERVER = localhost
PORT = 3306
USER = root
Password = abc
Database = mydb
and my odbcinst.ini file looks like this
# Example driver definitions
# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
[MySQL ODBC 5.3 Unicode Driver]
Driver = /usr/lib/libmyodbc5w.so
UsageCount = 1
[MySQL ODBC 5.3 ANSI Driver]
Driver = /usr/lib/libmyodbc5a.so
UsageCount = 1
And when I run command
isql qaz [root [abc]]
I get an error as
[ISQL]ERROR: Could not SQLConnect
Can Anyone tell me the issue and guide me with the correct way to set up odbc configurations in linux
I have done it successfully on windows though, but I am not too familiar with linux.
Thank you in advance
It's the ODBC driver (ODBC Connector) that is provided by mySQL. Did you pre-install the driver? Search how to install mysql odbc driver.
However, I would recommend using another mysql driver, like mysql/otp and not ODBC driver. I've had problems using the ODBC driver with mySql.
I have two systems. my first system is ubuntu 16.04. which, work as remote.
and another is centos 6. which, run in virtually. In centos, freeswitch installed. I have to send data from freeswitch to remote system means ubuntu.
on centos, my configuration of odbc.ini as :
[freeswitch]
DRIVER = /usr/lib64/libodbcmyS.so
SERVER = <ipaddress>
USER = root
PASSWORD = <password>
PORT = 3306
DATABASE = freeswitch
OPTION = 67108864
and odbcinst.int as below:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib64/libmyodbc.so
Setup = /usr/lib64/libodbcmyS.so
FileUsage = 1
Threading = 0
after setup above code.
I have to check odbc connection. for this, command fire as :
isql -v freeswitch
but, it show error as :
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
wrong driver description arise this type of error.
I have set proper driver description. wrongly, setup description mention in driver field.
I think you need to change the line
DRIVER = /usr/lib64/libodbcmyS.so
to
DRIVER = MySQL
Thanks.
I'm trying to make a connection via ODBC from a Python program running on Ubuntu to a MySQL box on the same machine. (I'm using ODBC instead of DB-API because I'm going to be using different database engines and I want a consistent way of getting to the system catalog, like SQLTables.)
But when I connect to my MySQL database and run SQLTables, I get this for my first row:
(u'\U0067007a\U005f0061\U00690062\U006c006c\U006e0069\U005f0067\U00750061\U006f0074\U0061006d\U00690074\U006e006f\U0063005f\U00630063',
u'', u'\U00750061\U00680074\U0067005f\U006f0072\U00700075',
u'\U00410054\U004c0042', u'')
Clearly these are unicode values, but they look like they are for really high codepoints, and sure enough, I can't encode them into ASCII. All my table names should be ASCII.
Is there some setting that I'm missing or have wrong that is causing this?
my odbc.ini is:
[ODBC Data Sources]
mu = MySQL
[mu]
Description = MySQL Database Test
Driver = MySQL
Server = localhost
Database = ccc2
Port = 3306
My odbcinst.ini is
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/odbc/libmyodbc.so
FileUsage = 1
Found it. I needed to specify Charset=UTF8 in my connection paramters, like so:
[ODBC Data Sources]
mu = MySQL
[mu]
Description = MySQL Database Test
Driver = MySQL
Server = localhost
Database = ccc2
Port = 3306
Charset = UTF8
I have my unixodbc odbc.ini configure file like this:
[test]
Driver = /usr/local/lib/libmyodbc5-5.1.8.so
Description = Connector/ODBC 5.1.8 Driver DSN
SERVER = 127.0.0.1
PORT = 3306
USER = root
Password =
DATABASE = test
OPTION =
SOCKET =
And the problem is that it will not use the database as specified above, which is 'test'.
What I have to do is to manually execute a direct sql to change to database and run my query:
SQLExecDirect(stmt, "USE test", SQL_NTS);
SQLExecDirect(stmt, "SELECT * FROM mytable", SQL_NTS);
Any idea on how should I get rid of the 'USE test' which is a mysql command.
Why is unixodbc not setting 'test' as the default db since it's already specified in the conf file?
As on windows the driver manager (unixODBC in this case) only acts on the Driver tag, all other entries in the DSN are up to the driver to interpret. It doesn't notice there is a database= entry and know by magic that in this driver it should execute a "USE" command, and for another call SQLSetConnectAttr( SQL_ATTR_CURRENT_CATALOG ).
On my copy of the MySQL driver, it certainly uses the database= entry. However, I would check that 1. The copy of the driver you are using is built to use the unixODBC lib to access the shared config file (libodbcinst.so), or the driver is reading it directly, and is reading the same ini file as unixODBC. Possibly check with strace to see what ini is opened after the driver is loaded. Maybe try setting ODBCINI=/path/to/your/odbc.ini
[test]
Driver = /usr/local/lib/libmyodbc5-5.1.8.so
Description = Connector/ODBC 5.1.8 Driver DSN
SERVER = 127.0.0.1
PORT = 3306
USER = root
Password =
**DATABASE** = test
**OPTION** = **3**
**SOCKET** =
and can change options between 1,2 too