473,837 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB2CMD in XP - DOS batch file

Folks,

I need to create a batch file that will do the following -

Establish a DB2 instance
Connect to a certain database
Get data using an sql and output it to a file

So, this is what I have done in my test.cmd file

My first command is -

"%ProgramFiles% \ibm\sqllib\bin \db2cmd" /i /w db2 connect to

<db> user <uid> using <pwd>

And this connects me fine.

My second command is -

"%ProgramFiles% \ibm\sqllib\bin \db2cmd" /i /w db2 -tvf

TimSConfqty.sql

This does not execute in batch mode - since it appears that a new
instance of a window was created. If I type in this command at the DOS
prompt created by the 1st command, it works fine. But, it never
executes from the batch test.cmd file. If I type exit at the DOS prompt
- the instance exits and test.cmd continues onto attempting to execute
the 2nd command (which fails, since the first window (instance ?) was
closed.

I think I understand the problem, don't know how to solve it. Well,
maybe I don't understand the problem. Any thoughts ?

Thanks.

Apr 19 '06 #1
7 21604
You've got yhe correct idea but missed one of the details. You need to
place the connect statement in the file with your query. A single
execution of db2cmd is all that's necessary.

Your primary concern should be long term storage of the file containing
the userid and password. If this is a secured database, you will need to
establish appropriate controls over the file(s) containing the password.
Other mechanisms can be used to enable providing a password without
physically storing it on a disk drive but they will add some complexity
to the batch job.
Philip Sherman

rh********@gmai l.com wrote:
Folks,

I need to create a batch file that will do the following -

Establish a DB2 instance
Connect to a certain database
Get data using an sql and output it to a file

So, this is what I have done in my test.cmd file

My first command is -

"%ProgramFiles% \ibm\sqllib\bin \db2cmd" /i /w db2 connect to

<db> user <uid> using <pwd>

And this connects me fine.

My second command is -

"%ProgramFiles% \ibm\sqllib\bin \db2cmd" /i /w db2 -tvf

TimSConfqty.sql

This does not execute in batch mode - since it appears that a new
instance of a window was created. If I type in this command at the DOS
prompt created by the 1st command, it works fine. But, it never
executes from the batch test.cmd file. If I type exit at the DOS prompt
- the instance exits and test.cmd continues onto attempting to execute
the 2nd command (which fails, since the first window (instance ?) was
closed.

I think I understand the problem, don't know how to solve it. Well,
maybe I don't understand the problem. Any thoughts ?

Thanks.

Apr 20 '06 #2
Solution offered by Norman W

Create a batch file to initialize a db2 command environment:
initdb2.bat
db2cmd -c -w -i %1.bat

Create a batch file with db2 and operating system commands:
runreport.bat
rem connect to database
db2 connect to sample user xxxx using xxxxx
rem run some sql and output to runreport.out
db2 -vf runreport.sql -z runreport.out

Create a file with sql:
runreport.sql
select count(*) from sysibm.systable s

Execute this with:
initdb2 runreport

Apr 20 '06 #3
Solution offered by Norman W

Create a batch file to initialize a db2 command environment:
initdb2.bat
db2cmd -c -w -i %1.bat

Create a batch file with db2 and operating system commands:
runreport.bat
rem connect to database
db2 connect to sample user xxxx using xxxxx
rem run some sql and output to runreport.out
db2 -vf runreport.sql -z runreport.out

Create a file with sql:
runreport.sql
select count(*) from sysibm.systable s

Execute this with:
initdb2 runreport

Apr 20 '06 #4
Phil, Thanks. I got this working. What are some of the options about
storing the password ?

Apr 20 '06 #5
This isn't the forum to discuss security issues in. The appropriate
answer to your question depends on your environment, security policies,
government regulations, input from your attorneys and probably a few
other factors.

Phil Sherman

Raj. wrote:
Phil, Thanks. I got this working. What are some of the options about
storing the password ?

Apr 21 '06 #6
Assuming that your using Windows 2000 or above.
Create an user environment variable and store the password in that
variable.

Since it is going to be an user shell environment varaible, other users
except the administrators will not be able to see this setting.

Then use it as follows
db2 connect to sample user xxxx using %password%

'%' s are required. Don't forget to put them around.

Pay back time:
This is something that I learnt from a great great DBI programmer..

regards,

Mehmet Baserdem

Apr 27 '06 #7

Create an user environment variable and store the password in it. (i.e.
mydb2password)

Since it is going to be an user shell environment variable, other users
except the administrators will not be able to see it.

Then use it as follows
db2 connect to sample user xxxx using %mydb2password%

'%' s are required. Don't forget to put them around.

Pay back time:
This is something that I learned from a great great DBI programmer..

regards,

Mehmet Baserdem

Apr 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
10159
by: SkySea | last post by:
Hi! Any help on this would be appreciated... In an HTML document that lists instructions on installing some software, there's a point where a DOS batch file needs to be run in order to copy files from the CD to the hard drive. Given that CD drives can have various names, I wanted to run the batch file using relative paths. The problem is, the DOS window that opens to run the batch file can leave the command prompt at any location . So...
1
15200
by: Rob | last post by:
I'm running a batch file using the Shell function. When I manually launch the batch file, the window remains open, since I use the 'pause' statement. But when I launch the batch file within Access, the Shell window becomes a blip on the screen and then is gone. Why does the Shell window not stay open on the screen? I want to visually verify that the batch file is functioning properly and then close the window myself. Am I missing a...
4
47554
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup) 4) Once the copy is complete, the batch file opens the Access database again 5) EXIT should close out the cmd window but it does not execute that line
3
4481
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see cmd.exe with ASPNET as a user. But nothing happens. It can't execute the batch file. This is the code i am using to run the batch file:
1
24315
by: steve | last post by:
Hi all, Here's some work in progress that should allow you to run a batch file as a custom action in a VS deployment project. Yup I know you can use js or wsh, but the target may not have either.. Essentially it's just a wrapper for the Process class and a command interpreter. Warning, it only partly works. I had wanted to pass in (a) The name of the batch file (through "BatchFileName"), and
4
13394
by: ed | last post by:
Hi all, I'm very new to vb (2nd day) and I need to create a small app that will replace my old batch file with a flashy gui. I had some experience with access 2.0 which helps ;) What I would like is to get the output of the batch file to display on the gui as the batch file is running. if some of you understand unix... I want this: tail -f /var/log/messages
7
31428
by: Nananana | last post by:
Hi. I have 2 DB2 statements: connect select How can I create a batch file and redirect the output to a file? I would like something like this:
2
11805
by: da123 | last post by:
I have a clean up proceudre that needs to be scheduled on weekly basis. My company owns a schedular that can kick off MS DOS Batch file for me. If only I can execute the stored procedure from a .BAT file my work will be done. I tried I created a simple batch file which uses DB2 CLP to execute the stored procedure, but I'm getting this error "SQL1024N A database connection does not exist. SQLSTATE=08003" when I run this batch file. ...
14
12838
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in case it's a question, i want to popup a messageBox or something, and bring back to the batch file the result (Yes\No question). I know how to excute the batch file and get all the Standard output at the end, but i don't know who can i read it line by...
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10886
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10580
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7817
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5674
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.