Solved

locking DB2 table using ODBC

Posted on 2002-05-29
9
334 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now