Nodejs and Sql server from linux - linux

I'm trying to connect from ubuntu (kubuntu 13.04) with nodejs to a sql server db! (sql server 2012)
I was looking at node odbc..
so.. I start installing FreeTds, then unixOdbc, then launch: npm install odbc
1) I configured the file "etc/freetds/freetds.conf" like this:
[FreeTDS]
host = gerry_win7
port = 1433
tds_version = 8.0
client charset = UTF-8
2) install sqsh (sudo apt-get install sqsh) and try to connect with
sqsh -S FreeTDS -U trm1 -P user
and execute a query: works perfectly!
3) then, I tried to configure ODBC access in this way:
file "/etc/odbcinst.ini":
[FreeTDS]
Description = TDS driver
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
file "/etc/odbc.ini":
[FreeTDS]
Driver = FreeTDS
Description = ODBC connectin via FreeTDS
Trace = No
Servername = gerry_win7
Database = testsql
UID = trm1
PWD = user
Port = 1433
4) with this sample code with nodejs I received the following error:
code:
var cn = 'DRIVER={FreeTDS};SERVER=gerry_win7;UID=trm1;PWD=user;DATABASE=testsql';
var Database = require('odbc').Database, db = new Database();
db.open(cn, function(err){
if (err) {return console.log(err);}
});
error:
[unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[Error: Error opening database]
but, as I wrote before, with the "sqsh" client the connection works: I can run queries!
can someone help me understand what I'm doing wrong?

This is the connection string I would use if I were specifying the DRIVER in it:
"DRIVER={FreeTDS};SERVERNAME=gerry_win7;DATABASE=testsql;UID=trm1;PWD=user;AutoTranslate=yes"
If you want to use the DSN that you have configured in /etc/odbc.ini then you would want to do:
"DSN=FreeTDS;UID=trm1;PWD=user;DATABASE=testsql"
Testing with the sqsh command may just use the configuration information that is in /etc/freetds/freetds.conf (citation needed). It is best to test your ODBC configuration (outside of node) with the isql command like:
$ isql FreeTDS trm1 user
Where FreeTDS is the DSN configured in /etc/odbc.ini.
Your configuration may be a little bit confusing because both the driver name and the DSN name are FreeTDS. I personally find it more helpful to use the server name or some other identifier as the DSN name specified in /etc/odbc.ini. I would suggest something like this in your odbc.ini:
[gerry]
Driver = FreeTDS
Description = ODBC connectin via FreeTDS
Trace = No
Servername = gerry_win7
Database = testsql
UID = trm1
PWD = user
Port = 1433
Then use this connection string:
"DSN=gerry;UID=trm1;PWD=user;DATABASE=testsql"
Doing it that way, you could potentially just change the Driver entry in the odbc.ini file if you want to use the SQL Server Native Client 11.0, if you get to that point. :)

Related

Connecting to postgresql from python 3, running in Cloud Shell: password authentication failed

I try to run locally (from GCP terminal) python 3 tutorial program to connect to my postgresql dsatabase.
I run proxy, as it is suggested in source:
./cloud_sql_proxy -instances=xxxxxxxx:us-central1:testpg=tcp:5432
it works, I can connect to it with:
psql "host=127.0.0.1 sslmode=disable dbname=guestbook user=postgres
Unfortunately when I try to connect from python:
cnx = psycopg2.connect(dbname=db_name, user=db_user,
password=db_password, host=host)
host is 121.0.0.1 -as I run it locally, I get this error:
psycopg2.OperationalError: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "postgres"
I can't get around what I miss?
Thanks in advance ...
I'd recommend using the Cloud SQL Python Connector to manage your connections and best of all you won't need to worry about running the proxy manually. It supports the pg8000 postgresql driver and can run from Cloud Shell.
Here is an example code snippet showing how to use it:
from google.cloud.sql.connector import connector
import sqlalchemy
# configure Cloud SQL Python Connector properties
def getconn() ->:
conn = connector.connect(
"xxxxxxxx:us-central1:testpg",
"pg8000",
user="YOUR_USER",
password="YOUR_PASSWORD",
db="YOUR_DB"
)
return conn
# create connection pool to re-use connections
pool = sqlalchemy.create_engine(
"postgresql+pg8000://",
creator=getconn,
)
# query or insert into Cloud SQL database
with pool.connect() as db_conn:
# query database
result = db_conn.execute("SELECT * from my_table").fetchall()
# Do something with the results
for row in result:
print(row)
For more detailed examples refer to the README of the repository.

Excel receive data from PostgreSQL using iODBC connector

I'm trying to using psqlODBC driver to receive data from PostgreSQL to Excel in macOS Catalina.
But I keep getting this error IM003 [iODBC][Driver Manager]Specified driver could not be loaded
Following things are the method I've tried but still don't succeed.
Disable SIP
Move psqlodbca.so under the /Library/ODBC folder in order to let Excel open in sandbox environment.
Changed original /usr/lib/libpq.5.dylib to PostgreSQL's dylib file by using command
sudo ln -s /postgresql_install_folder/lib/libpq.5.dylib /usr/lib/libpq.5.dylib
I download the source from https://www.postgresql.org/ftp/odbc/versions/src/ and follow this article https://odbc.postgresql.org/docs/unix-compilation.html to compile the driver and install the psqlodbca.so under /Library/ODBC
My /Library/ODBC/odbc.ini
[ODBC Data Sources]
postgresAscii = ascii
[postgresAscii]
Driver = {ascii}
Description = postgres odbc for user type ascii
Database = db
Server = 127.0.0.1
Port = 5432
FetchBufferSize = 99
My /Library/ODBC/odbcinst.ini
[ODBC Drivers]
ascii = Installed
[ascii]
Driver = /Library/ODBC/psqlodbca.so
Setup =
I can connected to my DB using iODBC Administrator64.app

Error psycopg2.OperationalError: fe_sendauth: no password supplied even after postgres authorized connection

My python script is raising an 'psycopg2.OperationalError: fe_sendauth: no password supplied' error, even though the Postgre server is authorizing the connect.
I am using Python 3.5, psycopg2, Postgre 9.5 and the password is stored in a .pgpass file. The script is part of a restful flask application, using flask-restful. The script is running on the same host as the Postgre server.
I am calling the connect function as follows:
conn_admin = psycopg2.connect("dbname=database user=username")
When I execute the script I get the following stack trace:
File "/var/www/flask/content_provider.py", line 84, in get_report
conn_admin = psycopg2.connect("dbname=database user=username")
File "/usr/local/lib/python3.5/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: fe_sendauth: no password supplied
However when I look at the Postgre server log I see the following (I enabled the logger to also show all connection requests):
2019-01-04 18:28:35 SAST [17736-2] username#database LOG: connection authorized: user=username database=database
This code is running fine on my development PC, however when I put it onto the Unbuntu server, I start getting this problem.
To try and find the issue, I have hard-coded the password into the connection string, but I still get the same error.
If I execute the above line directly into my Python terminal on the host, it works fine, with and without the password in the connection string.
EDIT:
One thing I did notice is that on my desktop I use Python 3.6.2, while on the server I use Python 3.5.2.
Try adding the host:
conn_admin = psycopg2.connect("dbname=database user=username host=localhost")
Try adding the password ie
conn = psycopg2.connect("dbname=database user=username host=localhost password=password")

how to configure component pubsub to tigase server in ubuntu machine(localhost)?

I have installed tigase server in my linux machine.
After successfully installed tigase i found following in etc/init.properties.
--user-db = mysql
--admins = admin#username
--user-db-uri = jdbc:mysql://localhost/tigasedb?user=tigase&password=tigase12
config-type = --gen-config-def
--virt-hosts = username
--debug = server
Now, I want to install pubsub component with already installed server.
You need to reinstall with advance configuration options instead of basic installation.
You will get options for which component you need to configure with server.

Monitor azure with nagios and odbc-freetds

I want to monitor Azure Paas database with Nagios. I'm using this plugin available at https://github.com/MsOpenTech/WaMo
When I try to check database:
./check_azure_sql.py -u -p -d -k top5queries
I get this error message:
('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')
Error connecting to database
All dependencies are installed (list in GitHub plugin site).
Here you can see my /etc/odbcinst.ini:
[ODBC]
Trace = Yes
TraceFile = /tmp/odbc.log
[FreeTDS]
Description = ODBC For TDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
Here you can see my /etc/freetds/freetds.conf:
# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
# A typical Sybase server
[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0
# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0
And my /etc/odbc.ini is empty.
Does anybody have any idea?
bhagdev, to do simple, i'm trying to monitor Sql database Azure Paas with nagios.
It's not me that is written the plugin available at github.com/MsOpenTech/WaMo. For a nagios admin, i only need to execute the command ./check_azure_sql.py -u (username) -p (password) -d (database) -k (key) (check_azure_sql.py written in python) from debian linux cli.
So when i execute the command above i get the error message :
('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)') Error connecting to database.
Than'ks for your help guy's

Resources