Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

locking DB2 table using ODBC

Posted on 2002-05-29
9
Medium Priority
?
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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