db2 cloud or ODBC connection to R - db2

Here i tried to setup my database service instance in ibm cloud DB2 and Access service credentials.
library(RODBC)
dsn_driver <- "{IBM DB2 ODBC Driver}"
dsn_database <- "bludb" # e.g. "bludb"
dsn_hostname <- "b1bc1829-6f45-4cd4-bef4-10cf081900bf.c1ogj3sd0tgtu0lqde00.databases.appdomain.cloud" # e.g "54a2f15b-5c0f-46df-8954-.databases.appdomain.cloud"
dsn_port <- "32304" # e.g. "32733"
dsn_protocol <- "TCPIP" # i.e. "TCPIP"
dsn_uid <- "xxxxxxxxx" # e.g. "zjh17769"
dsn_pwd <- "xxxxxxxxxxxxxxxx" # e.g. "zcwd4+8gbq9bm5k4"
dsn_security <- "ssl"
Then i Create a database connection
Create a connection string and connect:
conn_path <- paste("DRIVER=",dsn_driver,
";DATABASE=",dsn_database,
";HOSTNAME=",dsn_hostname,
";PORT=",dsn_port,
";PROTOCOL=",dsn_protocol,
";UID=",dsn_uid,
";PWD=",dsn_pwd,
";SECURITY=",dsn_security,
sep="")
conn <- odbcDriverConnect(conn_path)
but here i got this warning msg that the connection is field:
Warning messages:
1: In odbcDriverConnect(conn_path) :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect(conn_path) : ODBC connection failed
as i took the credentials information from the same cloud server as the below pic:
enter image description here
thank you
Hello i have question , i struggled when i try to connect the database in DB2 cloud to local R server , so i am a beginner and i found the steps for this are very mixed up so i downloaded the data bases to the DB2 cloud then i need to connect these datasets to R to do the sql functions as it requested in my course for IBM,

Related

unable to make connection between MSSQL and python image using Docker compose

I am using Docker compose to build images of python and MSSQL and making connection between DB and python app and added DB container as a server in python.connection file but getting errors like
pyodbc.OperationalError: ('08001', '[08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')
Adaptive Server is unavailable or does not exist
'DRIVER={FreeTDS};''SERVER=MSSQL_DB;''PORT=1433;' 'DATABASE=MYDATABASE;''TDS_Version=7.4', autocommit=True) my_python_app | pyodbc.OperationalError: ('08001', '[08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')

Oracle SQL Loader client unable to connect to server on LAN

I had a long running bash script/MySQL code to LOAD FILE into MySQL database.
I needed to convert this to Windows environment and Oracle DB. Wrote a PowerShell program and one of the lines in code uses sql loader to load files into oracle DB. The DB is in another system in LAN and I am connecting from a windows server system where I have installed the oracle full client (not just instant client) package.
Before using SQL Loader, I made sure that I am able to connect to DB from the system. The following SQL plus command works
Before using SQL Loader, I made sure that I am able to connect to DB from the system.
The following SQL plus command works
sqlplus abc/oracleabc#'"(description=(address=(host=192.168.22.44)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))"'
However I am not able to make SQL Loader work in PowerShell script.
I tried multiple command formats and connection strings
Try-1 :
sqlldr.exe abc/oracleabc#'"(description=(address=(host=192.168.22.44)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))"' control=$ctl_file_name direct='true'
Result :
LRM-00116: syntax error at 'address' following '('
Try-2:
sqlldr.exe 'abc/oracleabc#(description=(address=(host=192.168.22.44)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))' control=$ctl_file_name
Result :
LRM-00116: syntax error at 'address' following '('
Try-3
sqlldr.exe abc/oracleabc#"(DESCRIPTION\=(ADDRESS_LIST\=(ADDRESS\=(PROTOCOL\=TCP)(HOST\=192.168.22.44)(Port\=1521)))(CONNECT_DATA\=(SERVICE_NAME\=orcl)))" control=$ctl_file_name
Result:
SQL*Loader-704: Internal error: ulconnect:
OCIServerAttach [0]
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Try-4
sqlldr.exe userid=abc/oracleabc#ORCL control=$ctl_file_name
Result:
SQL*Loader-704: Internal error: ulconnect:
OCIServerAttach [0]
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Environmental variable ORACLE_HOME is defined in the system and points to client installation director D:\app\client\abc\product\19.0.0\client_1
tnanames.ora File :
# tnsnames.ora Network Configuration File:
D:\app\client\abc\product\19.0.0\client_1\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.22.44)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
sqlnet.ora File
# sqlnet.ora Network Configuration File:
D:\app\client\abc\product\19.0.0\client_1\NETWORK\ADMIN\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
TNS Ping:
C:\Users\abc>tnsping orcL
TNS Ping Utility for 64-bit Windows: Version 19.0.0.0.0 - Production on 04-MAY-2022
08:14:07
Used parameter files:
D:\app\client\abc\product\19.0.0\client_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =
192.168.22.44)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))
OK (20 msec)
Need help in identifying the connection parameter/format issue related to SQL Loader.

Deleted the DB2 Service Credentials. Created new credentials. New username and password not recognized for connection

#I'm using IBM DB2 on the cloud service (lite) of IBM. I deleted the DB2 Service Credentials but I didn't get to save the original password and username. I deleted that credential and created a new one. But using the ibm_db commands from python notebooks and sql to connect to the database, an error occurs:
SQLCODE=-30082ct: [IBM][CLI Driver] SQL30082N Security processing failed with reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001
I've tried repeatedly deleting and creating new service credentials but same error occurs. Not sure if I need the original or something. Is there a way to implement the password change without access to the original?
I use the following python code using a jupyter notebook. I assign the dsn_driver and others as a string e.g. dsn_uid = "abc1234".
import ibm_db
dsn = (
"DRIVER={0};"
"DATABASE={1};"
"HOSTNAME={2};"
"PORT={3};"
"PROTOCOL={4};"
"UID={5};"
"PWD={6};"
"SECURITY={7};").format(dsn_driver, dsn_database, dsn_hostname, dsn_port, dsn_protocol, dsn_uid, dsn_pwd,dsn_security)
try:
conn = ibm_db.connect(dsn, "", "")
print ("Connected to database: ", dsn_database, "as user: ", dsn_uid, "on host: ", dsn_hostname)
except:
print ("Unable to connect: ", ibm_db.conn_errormsg() )
RESULTS:

Access database which is running in EC2 instance through AWS-lambda function

I wrote the lambda function in python3.6 to access the postgresql database which is running in EC2 instance.
psycopg2.connect(user="<USER NAME>",
password="<PASSWORD>",
host="<EC2 IP Address>",
port="<PORT NUMBER>",
database="<DATABASE NAME>")
created deployment package with required dependencies as zip file and uploaded into AWS lambda.To build dependency i followed THIS reference guide.
And also configured Virtual Private Cloud (VPC) as default one and also included Ec2 instance details, but i couldn't get the connection from database. when trying to connect database from lambda result in timeout.
Lambda function:
from __future__ import print_function
import json
import ast,datetime
import psycopg2
def lambda_handler(event, context):
received_event = json.dumps(event, indent=2)
load = ast.literal_eval(received_event)
try:
connection = psycopg2.connect(user="<USER NAME>",
password="<PASSWORD>",
host="<EC2 IP Address>",
# host="localhost",
port="<PORT NUMBER>",
database="<DATABASE NAME>")
cursor = connection.cursor()
postgreSQL_select_Query = "select * from test_table limit 10"
cursor.execute(postgreSQL_select_Query)
print("Selecting rows from mobile table using cursor.fetchall")
mobile_records = cursor.fetchall()
print("Print each row and it's columns values")
for row in mobile_records:
print("Id = ", row[0], )
except (Exception,) as error :
print ("Error while fetching data from PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!'),
'dt' : str(datetime.datetime.now())
}
I googled quite a lot, But i couldn't found any workaround for this.is there any way to accomplish this requirement?
Your configuration would need to be:
A database in a VPC
The Lambda function configured to use the same VPC as the database
A security group on the Lambda function (Lambda-SG)
A security group on the Database (DB-SG) that permits inbound connects from Lambda-SG on the relevant database port
That is, DB-SG refers to Lambda-SG.
For lambda to connect to any resources inside a VPC, it needs to setup ENIs to the related private subnets of the VPC. Have you set up the VPC association and security groups of the EC2 correctly?
You can refer https://docs.aws.amazon.com/lambda/latest/dg/vpc.html

Logstash JDBC Input Plugin - DB2

I am trying to connect to DB2 database on Mainframe from my local machine. I am using JDBC input plugin. It seems the jdbc driver license file is not getting loaded. Can someone please tell me how can I load the db2jcc_license_cisuz-1.4.2.jar file.
I am using logstash version 6.2.2
I am able to connect to DB2 using the same license file from other Java applications.
My config file is as follows:
input {
beats {
port => 5044
}
jdbc {
jdbc_connection_string => "jdbc:db2://XX.XX.XX.XX:1304/DB91"
jdbc_user => "username"
jdbc_password => "password"
jdbc_driver_library => "C:\logstash-6.2.2\logstash-6.2.2\vendor\jruby\lib\jdbc\db2jcc-1.4.2.jar"
jdbc_driver_class => "com.ibm.db2.jcc.DB2Driver"
statement => "SELECT * from DBTPS29.NPSXTEI"
}
}
output {
stdout {codec => json_lines}
}
log file :
[2018-08-21T11:19:24,334][ERROR][logstash.inputs.jdbc ] Unable to connect to database. Tried 1 times {:error_message=>"Java::ComIbmDb2JccAm::SqlSyntaxErrorException: [jcc][t4][10509][13454][3.61.96] Connection to the data server failed. The IBM Data Server for JDBC and SQLJ license was invalid \r\nor was not activated for the DB2 for z/OS subsystem. If you are connecting directly to \r\nthe data server and using DB2 Connect Unlimited Edition for System z, perform the \r\nactivation step by running the activation program in the license activation kit. \r\nIf you are using any other edition of DB2 Connect, obtain the license file, \r\ndb2jcc_license_cisuz.jar, from the license activation kit, and follow the installation \r\ndirections to include the license file in the class path. ERRORCODE=-4230, SQLSTATE=42968"}
[2018-08-21T11:19:24,338][ERROR][logstash.pipeline ] A plugin had an unrecoverable error. Will restart this plugin.
Pipeline_id:main
Plugin: <LogStash::Inputs::Jdbc jdbc_connection_string=>"jdbc:db2://xx.xx.xx.xx:1304/DB91", jdbc_user=>"username", jdbc_password=>, jdbc_driver_library=>"C:\logstash-6.2.2\logstash-6.2.2\vendor\jruby\lib\jdbc\db2jcc-1.4.2.jar", jdbc_driver_class=>"com.ibm.db2.jcc.DB2Driver", statement=>"SELECT * from DBTPS29.NPSXTEI", id=>"f63556360d1928aaaf73cf6a06df9ec2cc1f8252c016d62da5830f446521927e", enable_metric=>true, codec=><LogStash::Codecs::Plain id=>"plain_bad95943-2146-4d84-a312-0be5db02acef", enable_metric=>true, charset=>"UTF-8">, jdbc_paging_enabled=>false, jdbc_page_size=>100000, jdbc_validate_connection=>false, jdbc_validation_timeout=>3600, jdbc_pool_timeout=>5, sql_log_level=>"info", connection_retry_attempts=>1, connection_retry_attempts_wait_time=>0.5, parameters=>{"sql_last_value"=>1970-01-01 00:00:00 UTC}, last_run_metadata_path=>"C:\Users\vipul.parikh/.logstash_jdbc_last_run", use_column_value=>false, tracking_column_type=>"numeric", clean_run=>false, record_last_run=>true, lowercase_column_names=>true>
Error: Java::ComIbmDb2JccAm::SqlSyntaxErrorException: [jcc][t4][10509][13454][3.61.96] Connection to the data server failed. The IBM Data Server for JDBC and SQLJ license was invalid
or was not activated for the DB2 for z/OS subsystem. If you are connecting directly to
the data server and using DB2 Connect Unlimited Edition for System z, perform the
activation step by running the activation program in the license activation kit.
If you are using any other edition of DB2 Connect, obtain the license file,
db2jcc_license_cisuz.jar, from the license activation kit, and follow the installation
directions to include the license file in the class path. ERRORCODE=-4230, SQLSTATE=42968
Exception: Sequel::DatabaseConnectionError
Stack: com.ibm.db2.jcc.am.ed.a(com/ibm/db2/jcc/am/ed.java:676)
com.ibm.db2.jcc.am.ed.a(com/ibm/db2/jcc/am/ed.java:60)
com.ibm.db2.jcc.am.ed.a(com/ibm/db2/jcc/am/ed.java:120)
com.ibm.db2.jcc.am.jb.Qb(com/ibm/db2/jcc/am/jb.java:4339)
com.ibm.db2.jcc.am.jb.b(com/ibm/db2/jcc/am/jb.java:4248)
com.ibm.db2.jcc.t4.b.b(com/ibm/db2/jcc/t4/b.java:537)
com.ibm.db2.jcc.t4.b.a(com/ibm/db2/jcc/t4/b.java:366)
com.ibm.db2.jcc.t4.b.(com/ibm/db2/jcc/t4/b.java:305)
com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(com/ibm/db2/jcc/DB2SimpleDataSource.java:214)
com.ibm.db2.jcc.DB2Driver.connect(com/ibm/db2/jcc/DB2Driver.java:460)
java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:498)
org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(org/jruby/javasupport/JavaMethod.java:468)
org.jruby.javasupport.JavaMethod.invokeDirect(org/jruby/javasupport/JavaMethod.java:326)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.adapters.jdbc.connect(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/adapters/jdbc.rb:203)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.connection_pool.make_new(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/connection_pool.rb:126)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.connection_pool.threaded.assign_connection(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/connection_pool/threaded.rb:192)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.connection_pool.threaded.acquire(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/connection_pool/threaded.rb:133)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.connection_pool.threaded.hold(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/connection_pool/threaded.rb:90)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.database.connecting.synchronize(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/database/connecting.rb:269)
`C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.database.connecting.test_connection(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/database/connecting.rb:279)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.database.connecting.connect(C:/logstash-6.2.2/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/sequel-5.4.0/lib/sequel/database/connecting.rb:58)
C_3a_.logstash_minus_6_dot_2_dot_2.logstash_minus_6_dot_2_dot_2.vendor.bundle.jruby.$2_dot_3_dot_0.gems.sequel_minus_5_dot_4_dot_0.lib.sequel.core.connect(C:/logstash-`
The license file name should be db2jcc_license_cisuz.jar and it should be in the same directory location as the db2jcc.jar or db2jcc4.jar. If these two are already verified to be true, then talk with your Z/OS DB2 DBA and ensure that the activation step has been performed for ...by running the activation program in the license activation kit. Your Z/OS DB2 DBA should know what that means and how to do it.