Using variables in cx_Oracle.connect method - python-2.x

I'm trying to read env.properties file to get the credentials to connect to Oracle DB using cx_Oracle.
Variables have correct values but I guess issue is with the way I'm using connect method.
Is there something wrong?
config = ConfigParser.RawConfigParser()
config.read('env.properties')
user = config.get('DatabaseSection', 'database.user')
pwd = config.get('DatabaseSection', 'database.password')
host = config.get('DatabaseSection', 'database.db_host')
port = config.get('DatabaseSection', 'database.db_port')
instance = config.get('DatabaseSection', 'database.db_instance')
conn = cx_Oracle.connect(user,pwd,host:port/instance)
cur = conn.cursor()

Managed with below piece of code -
dsn_tns = cx_Oracle.makedsn(host, port, instance)
conn = cx_Oracle.connect(user=user, password=pwd, dsn=dsn_tns)

Related

Sphinx + Oracle : Data source name not found error

I want to connect to remote oracle database server and index some data from there with sphinx search engine. My OS is ubuntu 16.04 and I havc installed sphinx on it and tested it with local mysql database and everthing was ok (All the data indexed and I could search and results was correct) . I also have installed unixODBC and tested it with isql tool to remote access to oracle database server and every thing was ok, but when I want to index data with indexer command of sphinx this error occure:
sql_connect: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
Here is source block of my sphinx.conf file:
source src2
{
type = odbc
sql_host = hostName
sql_user = user
sql_pass = pass
sql_db = dbname
sql_port = 1521
odbc_dsn = DSN = mydsn; Driver={Oracle};Dbq=hostname:1521/dbname;Uid=user;Pwd=pass
sql_query = \
SELECT tableId, Name \
FROM sampleTable
}
And odbc.ini file:
[mydsn]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
BindAsFLOAT = F
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = Oracle
DSN = mydsn
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MaxLargeData = 0
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = MYDATABASE
SQLGetData extensions = F
Translation DLL =
Translation Option = 0
DisableRULEHint = T
UserID = user
Password = pass
StatementCache=F
CacheBufferSize=20
UseOCIDescribeAny=F
SQLTranslateErrors=F
MaxTokenSize=8192
AggregateSQLType=FLOAT
and odbcinst.ini file :
[Oracle]
Description= ODBC for Oracle
Driver = /opt/oracle/instantclient_12_2/libsqora.so.12.1
Setup =
FileUsage = 1
CPTimeout =
CPReuse = /usr/local/etc/odbcinst.ini
Try
odbc_dsn = DSN=mydsn;
i.e. w/o spaces around = after the DSN and since you have everything else specified in the ini file just the DNS should be enough. You also need only sql_query out of the rest sql_*. Like this:
source src2
{
type = odbc
odbc_dsn = DSN=mydsn;
sql_query = \
SELECT tableId, Name \
FROM sampleTable
}

How to create EC2 instance through boto python code

requests = [conn.request_spot_instances(price=0.0034, image_id='ami-6989a659', count=1,type='one-time', instance_type='m1.micro')]
I used the following code. But it is not working.
Use the following code to create instance from python command line.
import boto.ec2
conn = boto.ec2.connect_to_region(
"us-west-2",
aws_access_key_id="<aws access key>",
aws_secret_access_key="<aws secret key>",
)
conn = boto.ec2.connect_to_region("us-west-2")
conn.run_instances(
"<ami-image-id>",
key_name="myKey",
instance_type="t2.micro",
security_groups=["your-security-group-here"],
)
To create an EC2 instance using Python on AWS, you need to have "aws_access_key_id_value" and "aws_secret_access_key_value".
You can store such variables in config.properties and write your code in create-ec2-instance.py file
Create a config.properties and save the following code in it.
aws_access_key_id_value='YOUR-ACCESS-KEY-OF-THE-AWS-ACCOUNT'
aws_secret_access_key_value='YOUR-SECRETE-KEY-OF-THE-AWS-ACCOUNT'
region_name_value='region'
ImageId_value = 'ami-id'
MinCount_value = 1
MaxCount_value = 1
InstanceType_value = 't2.micro'
KeyName_value = 'name-of-ssh-key'
Create create-ec2-instance.py and save the following code in it.
import boto3
def getVarFromFile(filename):
import imp
f = open(filename)
global data
data = imp.load_source('data', '', f)
f.close()
getVarFromFile('config.properties')
ec2 = boto3.resource(
'ec2',
aws_access_key_id=data.aws_access_key_id_value,
aws_secret_access_key=data.aws_secret_access_key_value,
region_name=data.region_name_value
)
instance = ec2.create_instances(
ImageId = data.ImageId_value,
MinCount = data.MinCount_value,
MaxCount = data.MaxCount_value,
InstanceType = data.InstanceType_value,
KeyName = data.KeyName_value)
print (instance[0].id)
Use the following command to execute the python code.
python create-ec2-instance.py

Error while configuring EMS with Database in Fault Tolerant mode

I am trying to setup my EMS in FT Mode, I have configured all the parameters in the 2 EMS config files.
But Im getting the warning:
Unable to initialize fault tolerant connection, remote server returned 'invalid user name'
Servername and password are exactly the same in both config files,so I don't know where the error is.
I am attaching the EMS config files that i am using for the EMS servers:
tibemsd.conf:
authorization = enabled
password =
server=EMS-HakanLAL
listen=tcp://7222
Ft_active=tcp://8222
users = users.conf
groups = groups.conf
topics = topics.conf
queues = queues.conf
acl_list = acl.conf
factories = factories.conf
routes = routes.conf
bridges = bridges.conf
transports = transports.conf
tibrvcm = tibrvcm.conf
durables = durables.conf
channels = channels.conf
stores = stores.conf
store = "C:/temp"
tibemsdft.conf:
authorization = enabled
password =
server=EMS-HakanLAL
listen=tcp://8222
Ft_active=tcp://7222
users = C:\Tibco\ems\8.1\BackUp\users.conf
groups = C:\Tibco\ems\8.1\BackUp\groups.conf
topics = C:\Tibco\ems\8.1\BackUp\topics.conf
queues = C:\Tibco\ems\8.1\BackUp\queues.conf
acl_list = C:\Tibco\ems\8.1\BackUp\acl.conf
factories = C:\Tibco\ems\8.1\BackUp\factories.conf
routes = C:\Tibco\ems\8.1\BackUp\routes.conf
bridges = C:\Tibco\ems\8.1\BackUp\bridges.conf
transports = C:\Tibco\ems\8.1\BackUp\transports.conf
tibrvcm = C:\Tibco\ems\8.1\BackUp\tibrvcm.conf
durables = C:\Tibco\ems\8.1\BackUp\durables.conf
channels = C:\Tibco\ems\8.1\BackUp\channels.conf
stores = C:\Tibco\ems\8.1\BackUp\stores.conf
store = "C:\ProgramData\TIBCO3\tibco\cfgmgmt\ems\data"
your tibemsd.conf and tibemsdft.conf looks fine. What you are probably missing is registering the server-name as a user within the users.conf.
If you make that entry, both servers should be able to connect to each other.

Erlang Heroku RabbitMQ

i run in terminal command
heroku config:get RABBITMQ_BIGWIG_RX_URL --app app1
give me a string
amqp://Ajwj23X3:nsi3sC#leaping-charlock-1.bigwig.lshift.net:18372/Hbau2x3d
I copy login,password,url,port to erlang code
-record(amqp_params_network, {username = <<"Ajwj23X3">>,
password = <<"nsi3sC">>,
virtual_host = <<"/">>,
host = "leaping-charlock-1.bigwig.lshift.net",
port = 18372,
channel_max = 0,
frame_max = 0,
heartbeat = 0,
connection_timeout = infinity,
ssl_options = none,
auth_mechanisms =
[fun amqp_auth_mechanisms:plain/3,
fun amqp_auth_mechanisms:amqplain/3],
client_properties = [],
socket_options = []}).
But when i run program and connection false
How correctly write amqp_params_network in erlang for heroku rabbitqm?
-record is the definition of the record type, and the values contained there are just defaults. It would be rather unusual to hard-code connection parameters as defaults for the record, even more so when the record definition is provided by an external library.
Instead, construct a record instance with the required data:
Params = #amqp_params_network{username = <<"Ajwj23X3">>,
password = <<"nsi3sC">>,
host = "leaping-charlock-1.bigwig.lshift.net",
port = 18372},
and use that instance when connecting:
{ok, Connection} = amqp_connection:start(Params),

proc - Connect to remote oracle database

I'm trying to connect to oracle DB on remote server:
userid = getenv("ORACLE_USER");
oracle_password = getenv("ORACLE_USER_PASSWORD");
db_name = getenv("DB_NAME");
EXEC SQL CONNECT :userid IDENTIFIED BY :oracle_password USING :db_name;
I get an error: ORA-01034.
I'd be happy for help. Thanks.
EXEC SQL BEGIN DECLARE SECTION;
userid VARCHAR(50);
oracle_password VARCHAR(50);
db_name VARCHAR(50);
EXEC SQL END DECLARE SECTION;
main()
{
userid.arr = getenv("ORACLE_USER");
userid.len = strlen(userid.arr);
oracle_password.arr = getenv("ORACLE_USER_PASSWORD");
oracle_password.len = strlen(oracle_password.arr);
db_name.arr = getenv("DB_NAME");
db_name.len = strlen(db_name.arr);
EXEC SQL CONNECT :userid IDENTIFIED BY :oracle_password USING :db_name;
if (sqlca.sqlcode==0)
{
prnitf("sucessful");
}
else
{
printf("failed");
return;
}
}
Hope it may be useful to you.
You will get ORA-01034 error when the database was not started up.
Possible causes include the following:
The SGA requires more space than was allocated for it.
The operating-system variable pointing to the instance is improperly defined.
Following line may resolve you issues
Check out link
First of all, use the alternative format:
EXEC SQL CONNECT :usr_pwd;
where the host variable usr_pwd contains your username and password separated by a slash character (/).
Then for usr_pwd attach remote server info:
"user/pwd#(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = xxxx)))(CONNECT_DATA = (SERVICE_NAME = xxxxx)))"
For fast verification, you can use sqlplus to see if it connects first then plug in your code and compile:
sqlplus user/pwd#(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = xxxx)))(CONNECT_DATA = (SERVICE_NAME = xxxxx)))

Resources