Solved

locking DB2 table using ODBC

Posted on 2002-05-29
9
337 Views
Last Modified: 2010-08-05
Hello all:

I'm having a little trouble with LOCK TABLE statement. It does not work. I'm using VBasic and ODBC to
do it.

LOCK TABLE mytable in EXCLUSIVE MODE

but after that any other user can acces this table without any problem.

Any idea?

thanks


0
Comment
Question by:josevillar
9 Comments
 
LVL 1

Expert Comment

by:jdc0724
ID: 7042916
Howdy, you need to specify the appropriate options on your "openConnection()" method.  Use the following code to connect to DB2 and lock the table:

Dim wsRepository as DAO.Workspace
Dim conDb2 as DAO.Connection
dim recDb2 as DAO.Recordset

Set wsRepository = CreateWorkspace("", "", "", dbUseODBC)
set conDb2 = wsRepository.OpenConnection("DB2P", dbDriverNoPrompt, False, "ODBC;UID=DPWGIS00;PWD=INST8BER")

The parms in the OpenConnection method are as follows:
1. A registered ODBC Datasource Name
2. Indicating to ODBC that we will fill in all necessary connection information (password, ect) in the OpenConnection method instead of in the ODBC DSN entry.
3. This indicates you want Read/Write access to the DB2 table.
4. These are the connection parms used by ODBC to establish a connection.  These will be put in place by your local DBA or IT security administrator.

Once you have gotten this far you can specify many different combinations to Lock the data in your particular table right in the "openRecordset()" method.  This is a much better approach.  You can allow other users to view the data without the ability to change it.  For instance you can use the constant "dbDenyRead" in the options parameter of your openRecordset() method.  There is also a "dbDenyWrite".  

For example:  Set recDb2 = conDb2.OpenRecordset(strSql, ,dbDenyRead, dbSqlPassThrough);

You might consider only locking the records you intend to be updating.  It is inefficient to lock a complete DB2 table from others unless you absolutely have to.  Anyway, using the approach above, you can chose to do it anyway you want.

Hope this helps.
JDC0724
0
 

Author Comment

by:josevillar
ID: 7043920
Thank you for your answer but I forgot to tell I'm using DAO not ADO.

sConnectString= "ODBC;UID=" + sUser + ";" + "PWD=" + sPassword + ";DSN=" + sDataBase
Set Base = OpenDatabase(sDataBase, dbDriverNoPrompt, False, sConnectString)

Do you know the way now???

Thank you

0
 
LVL 1

Expert Comment

by:jdc0724
ID: 7047133
The way I showed you is also using DAO.  The only difference is that you are using a Database Object instead of a Connection Object.  If you look at the parms you specified in your OpenDatabase call they are almost identical to the ones in the Connection object.  I believe that by using the Database object, which you are, you are are forced to use JET instead of ODBC.  They question now is.... What database are you using??  If you are using Oracle, DB2, MySQL, etc, you should use the approach I have shown you above.  In fact, the only time I use a database object is when I am working with FoxPro files (.dbf) or sometimes with MSAccess.
Another thing to keep in mind that using access you cannot lock at the row level like you can in Oracle and Db2.

Just one more thing, in your last example:
   >>> sConnectString= "ODBC;UID=" + sUser + ";" + "PWD=" + sPassword + ";DSN=" + sDataBase

You should definitely use the concatenation character "&" instead of "+".  It happens to work for you in this scenario but could reek havac had their been any numerical values in your string...  Just a thought.  Let me know what database you are using.

Thanks,
JDC

0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:josevillar
ID: 7050819
I have tried your example using Connection objetct instead of Database but when I try to open the recordset I get "3001 invalid argument" error.

I'm using DB2 database

0
 
LVL 1

Expert Comment

by:jdc0724
ID: 7051093
Is it a problem in your Sql string?  Send me the code from creating the Workspace to opening the recordset so I can see it.
0
 

Author Comment

by:josevillar
ID: 7051117
This is my code:

sConnectString = "ODBC;UID=" + sUser + ";" + "PWD=" + sPassword + ";DSN=" + sDataBase

Set wsRepository = CreateWorkspace("", "", "", dbUseODBC)

Set conDb2 = wsRepository.OpenConnection(sDataBase, dbDriverNoPrompt, False, sConnectString)

sSQL = "select * from db2admin.maximo"

Set recDb2 = conDb2.OpenRecordset(sSQL, , dbSQLPassThrough, dbDenyRead)



0
 
LVL 1

Accepted Solution

by:
jdc0724 earned 100 total points
ID: 7051147
Yes, I see an invalid argument error here:  You need to remove the comma between "dbsqlpassthrough" and "dbdenyread".  Vb will view the comma as a seperate parameter and the function "openRecordsSet" is not set up to be able to recieve another argument.  You shoud append the two values together instead.  Use this:

Set recDb2 = conDb2.OpenRecordset(sSQL, , dbSQLPassThrough & dbDenyRead)  

This should fix that problem.  If for some reason it dosen't work, remove the "& dbdenyRead) and just try the recordset without it.  However, the example I gave you able should definitely get you through the other problem.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7851258
Hi josevillar,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept jdc0724's comment(s) as an answer.

josevillar, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7912855
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question