Prevent timeout when connecting - groovy

I am using groovy to connect to a database and it works great with one my sources. Recently, I have access to another database but I can seem to connect to it using Groovy.
I get the error(s):
Dec 20, 2013 12:22:26 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNING: Sanitizing stacktrace:
oracle.net.ns.NetException: The Network Adapter could not establish the connection
Is there a way to extend the connection so it won't time out?
def db = Sql.newInstance(
'jdbc:oracle:thin:#10.10.18.75:1521:radd',
'report_user', 'createreport', 'oracle.jdbc.pool.OracleDataSource')

According to the Groovy API for newInstance You should be able to pass in properties key value pairs and for Oracle use the ConnectionWaitTimeout property.
def db = Sql.newInstance(
url: 'jdbc:oracle:thin:#10.10.18.75:1521:radd',
user: 'report_user', password: 'createreport', driverClassName: 'oracle.jdbc.pool.OracleDataSource', connectionWaitTimeout: 10)

Related

Connecting to Aurora Postgres (Babelfish, 1433)

I'm attempting to connect to a new Aurora PostgreSQL instance with Babelfish enabled.
NOTE: I am able to connect to the instance using the pg library through the normal port 5432 (the Postgres TDAS endpoint).
However, for this test, I am attempting to connect through the Babelfish TDS endpoint (1433) using the standard mssql package.
If I specify a database name (it is correct), I receive the error 'database "postgres" does not exist':
var config = {
server: 'xxx.us-east-1.rds.amazonaws.com',
database: 'postgres',
user: 'xxx',
password: 'xxx'
};
and the connection closes since the connection fails.
if I omit the database property in the config, like:
var config = {
server: 'xxx.us-east-1.rds.amazonaws.com',
user: 'xxx',
password: 'xxx'
};
It will connect. Also, I can use that connection to query basic things like SELECT CURRENT_TIMESTAMP and it works!
However, I can't access any tables.
If I run:
SELECT COUNT(1) FROM PERSON
I receive an error 'relation "person" does not exist'.
If I dot-notate it:
SELECT COUNT(1) FROM postgres.dbo."PERSON"
I receive an error "Cross DB query is not supported".
So, I can't connect to the specific database directly and if I connect without specifying a database, I can't cross-query to the table.
Any one done this yet?
Or, if not, any ideas on helping me figure out what to try next? I'm out of ideas.
Babelfish databases (that you connect to on port 1433) have nothing to do with PostgreSQL databases (port 5432). Essentially, all of Babelfish lives within a single PostgreSQL database (parameter babelfishpg_tsql.database_name).
You seem to have a single-db setup, because Cross DB query is not supported. With such a setup, you can only have a single database via port 1433 (apart from master and tempdb). You have to use CREATE DATABASE to create that single database (if it isn't already created; ask sys.databases).
I can't tell if it is supported to create a table in PostgreSQL (port 5432) and use it on port 1433 (the other way around is fine), but if so, you have to create it in a schema that you created with CREATE SCHEMA while connected on port 1433.
The answer was that I should be connecting to database "master".
Even though there is no database titled master in the instance, you still do connect to it.
Once connected, running the following:
select current_database();
This will indicate you are connected to database "babelfish_db".
I don't know how that works or why a database would have an undocumented alias.
The bigger answer here is that cross-DB object references are not currently supported in Babelfish, outside your current SQL Server database.
This is currently being worked on. Stay tuned.

Connection setup for Teams webhook on airflow is giving General Error <class 'sqlalchemy.exc.DataError'>

I need to send notification of failed DAG from airflow to Teams channel.
From Teams I have captured the incoming webhook link and when I add it in Airflow UI - Admin - Connection - New connection I am getting General Error class 'sqlalchemy.exc.DataError'
Connection settings are as below-
Conn Id: mycon
Conn Type: HTTP
Host: webhookuri
schema: http
Let me know if you know any resolution for this
I had a similar issue and the problem was the that the DB has a restriction of 100 maximum characters for the field host.
Have you try storing the connection in environment variables?
https://airflow.apache.org/docs/apache-airflow/stable/howto/connection.html#storing-a-connection-in-environment-variables
It should be something like:
export AIRFLOW_CONN_MSTEAMS_WEBHOOK_URL=<your_msteams_webhook_url>

Connection sasl conversation error(authentication error) while using mongoexport

I am trying to export data from a mongodb cluster to my computer, using my URI connection string, but am getting the error: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-S HA-1": (AtlasError) bad auth Authentication failed
This is the command I am using:
mongoexport --uri="mongodb+srv://yash_verma:<******>#jspsych-eymdu.mongodb.net/test?retryWrites=true&w=majority" --collection=entries --out=entries.csv
Could anyone tell me what it is that I am doing wrong? I am sure I am using the correct password.
I am also fairly new to programming and have tried to look online for a solution, but haven't found one yet.
Any help would be greatly appreciated.
Thanks,
Yash.
Your connection string looks fine, but make sure to remove the angle brackets (<>) around <password>, like so:
mongoexport --uri="mongodb+srv://yash_verma:******#jspsych-eymdu.mongodb.net/test?retryWrites=true&w=majority" --collection=entries --out=entries.csv
…where ****** is the database password (not the account password!) of the database user yash_verma.
Duplicate answer

Why can't I connect to Oracle DB with SQLAlchemy?

I'm trying to connect to a oracle DB with SQLAlchemy however I get the following error:
ORA-12545: Connect failed because target host or object does not exist
Note that the code running this is on a docker container that is located on a vm in GCP.
I tried using tools like telnet, curl, nmap, etc and they all are able to connect/say open. So I don't see why connecting through python would all of a sudden make it not visible.
Here is the code that is used to try to connect.
from sqlalchemy.orm.session import sessionmaker
from framework.db import BuildOracleConnection
Creds_Oracle = {
'userName': 'urname',
'password': 'pass',
'host': '10.10.10.10',
'port': '1521',
'serviceName': 'svcName'
}
Conn_Oracle = BuildOracleConnection(Creds_Oracle)
metaConn = sessionmaker(bind=Conn_Oracle)
metaSession = metaConn()
sql = 'select * from table'
sql = sql.replace('\n', ' ')
sourceExtract = metaSession.execute(sql)
The part that throws the error is the last line.
I expect to be able to connect but instead I get the following error:
ORA-12545: Connect failed because target host or object does not exist.
For some reason I wasn't able to connect directly to the loadbalancer, instead I had to connect to the nodes themselves.

Pull Syslog from the server using Groovy in Jira

I am new to Groovy in Jira, and I am trying to pull syslogs off a certain database. I am wondering if anyone can put me to the right direction. I am using the script console to implement this.
I am guessing it will be on the local host. I am given these to access the database server :
-Database server with Port Number
-Database name
-Password
-Application Database User
-Syslog Servers
Are there any tutorials I can use to be able to connect to the database server
Thank you very much,
Groovy provides the Sql class to simplify connecting to JDBC data sources. Here's an example.
import groovy.sql.Sql
def jdbc = 'jdbc:h2:mem:'
def db = Sql.newInstance(jdbc, 'org.h2.Driver')
def foos = db.rows('select foo from bar')
...
db.close() // Done with connection
The driver and JDBC connection string depends on the DBMS you're connecting to (MySQL, PostgreSQL, etc).
PostgreSQL example
Here's how to connect to PostgreSQL. The code below uses Groovy's Grape to download dependencies.
Note: #GrabConfig is required to load the org.postgresql.Driver class in a way that allows jdbc to find it.
#Grab('org.postgresql:postgresql:9.3-1101-jdbc41')
#GrabConfig(systemClassLoader=true)
import groovy.sql.Sql
def host = '192.168.1.1'
def port = 5432
def dbname = 'foo'
def user = 'xxx'
def password = 'yyy'
def jdbc = "jdbc:postgresql://${host}:${port}/${dbname}"
def db = Sql.newInstance(jdbc, user, password, 'org.postgresql.Driver')

Resources