DB2 ODBC Connection String without Database Name - db2

I am trying to connect DB2 Server with ODBC, which is working fine if I specify Database in connection string.
driver = 'IBM DB2 ODBC DRIVER'
server = '10.30.30.114'
port = '50000'
protocol = 'TCPIP'
database = 'SAMPLE'
user = 'administrator'
pass = 'password'
DBI.connect("DBI:ODBC:Driver=#{driver};HostName=#{server};Port=#{port};Protocol=#{protocol};Database=#{database};Uid=#{user};Pwd=#{pass};")
The issue is I will not be knowing the database name in advance at the time of connecting to the server. I want the list of databases on the server and then tables in those databases, how should I approach?

You cannot "connect to a DB2 server" via ODBC; you can only connect to a database, for which you obviously need to specify the database name. You could use the DB2 C/C++ API calls db2DbDirOpenScan and db2DbDirGetNextEntry to list the database directory, but this code will need to be executed on the server itself, otherwise it will attempt to list the database catalog on the client machine.

IF you are connecting to DB2 for i server (formerly DB2 UDB on OS/400) --
Initially connect using hostname, allowing database to default. You can then get a list of databases in the DB2 for i SYSCATALOGS view. Your query might look like this:
SELECT catalog_name, -- database name
catalog_text -- DB description
FROM QSYS2.SYSCATALOGS
WHERE catalog_type='LOCAL' -- local to that host
AND catalog_status='AVAILABLE' -- REMOTE catalogs are 'UNKNOWN' status
You could then connect to that database if . Once connected to the appropriate database, you could query other DB2 for i catalog views such as SYSSCHEMAS and SYSTABLES. ODBC/JDBC Catalog views and ANS/ISO Catalog views would also be available.
Other API's are available outside of an ODBC connection via IBM i Access, if you prefer.

Related

Informatica DB2 DSN not working in Designer

I am trying to connect to DB2 database to import source structure. I tried using ODBC DB2 Wire Protocol Driver Setup. I provided IP Address, TCP Port, Location ( DB2 to Z/OS and Iseries), but when I click on test connection I get below error:
[Informatica][ODBC DB2 Wire Protocol driver][DB2]NULLID.DDOS510A DOES NOT HAVE PRIVILEGE TO PERFORM OPERATION PACKAGE ON THIS OBJECT.
Same method I tried in lower environment of DB2 and connection works. but in higher environment I get this error. ( I verified login in the database directly and my user id has login access).
This is not a programming question, it is about configuration.
The reason that it works on one database, but fails on another, is because only one of the databases has the correct permissions.
Ask the DBA to grant relevant privileges to the userid at the database.
You will find more details at the following IBM technote and also at here.

DB2 CLP connect to remote DB

I downloaded and installed on Windows the following:
IBM DB2 Runtime Client (64-Bit) 10.5
with the aim of connecting to a remote server database.
It installed here:
C:\Program Files\IBM\SQLLIB
But I don't see any DB2 folders in there.
I tried to catalog the remote db like this:
db2 catalog tcpip node testing remote the.server.com server 446
If I then try to connect to it, I get the following:
SQL1031N The database directory cannot be found on the indicated file system.
There is some wizard installed called the 'Default DB2 and IBM Database Client Interface Selection Wizard'. I ran this and it said it would create a default DB2 copy and would be used by default, called DB2COPY1 and it would be installed to C:\Program Files\IBM\SQLLIB.
But I'm nnot sure what this is doing really.
What do I need to do here to connect to the remote DB2??
EDIT:
I have managed to get a bit further based on this article here:
https://www-01.ibm.com/support/docview.wss?uid=swg21008914
my current commands look like:
db2 catalog tcpip node tstnode remote my.server.com server 446
db2 catalog db db1name as mytstdb at node tstnode authentication server
db2 catalog dcs db db1name as A123456DAT
db2 terminate
db2 connect to mytstdb user <username> using <password>
However the connect fails with:
SQL30061N The database alias or database name "A123456DAT " was not
found at the remote node. SQLSTATE=08004
Any ideas?
If you are connecting through port 446, I guess you are trying to connect to DB2 for IBM z or DB2 for IBM i. If yes, you will need at least Db2 Connect.
Regarding error "SQL30061N The database alias or database name "A123456DAT " was not found at the remote node. SQLSTATE=08004" it happens to me when the userid does not have some priviledges on the source system. If it is an IBM i, look at the corresponding spool file. DRDA Connections are attended by jobs called QRWTSRVR. With the IBM i command WRKSPLF SELECT(USERID) (changing USERID by the user trying the DRDA connection) you can see the spool files for jobs related to your connection. Usually spool file messages are very specific on the cause of the failure.
If you are trying to connect to DB2 on z, I don't have experience.

PostgreSQL: One database to multiple user

I have PostgreSQL 9.3 version. I have created database name db1 now I need it to share with other users who all are connected with the LAN's to connect other applications with the same database.
In SQL Server: We can do this by selecting server name with login details.
Question:
Is it possible in PostgreSQL?
If yes, how can do this?
What is the procedure?
You will need to modify pg_hba.conf to allow remote connections to the database. Information about pg_hba.conf can be found here.
After that, you can connect programatically with a connection string, or similar to your image, with a GUI application like pgAdmin.
To connect (remotely or locally) from pgAdmin choose File -> Add Server... and enter the connection information into the dialog box. Here's an example of the window:
Your client computers will also need to have PostgreSQL drivers as well. If you're doing this in Windows, you'll probably be using ODBC. The PostgreSQL ODBC drivers are here. Info on the connection string format can be found here.
Here's an example of what pgAdmin looks like:

Can firebird database connect to other databases using like linked server in SQL Server?

I know that SQL Server has linked server that allow it to connect to other database and execute query. Now I am using firebird. I wonder if firebird has its "linked server" to access other databases. Thanks!
Firebird doesn't have a linked server feature. There is a limited method for accessing other Firebird databases (either remote or locally) using EXECUTE STATEMENT, however this only supports Firebird database, and you need to provide the data source information on each invocation.

How to connect to particular database in Oracle 10g

Suppose I have multiple Oracle databases in the same server. Now I want to connect to particular database and query a table just like SQL Server 2008. How to start particular Oracle database?
If you are using SQL*Plus, the most common syntax for opening a connection is
sqlplus user_name/password#tns_alias
In this example TNS_ALIAS is the TNS alias for the particular database you want to connect to (most likely "XE" based on your followups to inium's answer). If you want to connect to a different database, you would need to specify a TNS alias for that specific database.
Note that since you are coming from a SQL Server background, the SQL Server definition of a database is rather different than the Oracle definition. What SQL Server calls a database is similar logically to what Oracle calls a schema (and similar physically to what Oracle calls a tablespace). So when you're dealing with Oracle, it's much more common to have many schemas in a single database than to have a large number of databases on a server. This is particularly true if you're using the Express Edition (Oracle XE) where you're generally limited to one database per machine.
go to cmd and type sqlplus <database-name>/<database-password>
You can use SQL Developer, it's similar to SQL Enterprise Manager 2005. Just create a new connection using the db user name and password.