Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

locking DB2 table using ODBC

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
josevillar
Asked:
josevillar
1 Solution
 
jdc0724Commented:
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
 
josevillarAuthor Commented:
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
 
jdc0724Commented:
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
Technology Partners: 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!

 
josevillarAuthor Commented:
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
 
jdc0724Commented:
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
 
josevillarAuthor Commented:
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
 
jdc0724Commented:
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
 
DanRollinsCommented:
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
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now