01-14-2017 05:11 PM - edited 01-14-2017 05:11 PM
Hello,
Just have a quick question about the SQL toolkit (v2.3).
Is there a way to lock an ms sql database upon connection?
I'm currently doing the following sequence:
DBConnect()
DBSetDatabase()
DBActivateSQL()
DBFree()
DBDisconnect()
However, when I do a connect, I don't want to have a same application to be able to read the database.
My understanding is that if I create 2 separate executable with the same functions both .exe will be able to access the ms sql database at the same time.
I tried to implement an optimistic concurrency but I don't think it's working.
01-15-2017 09:48 AM
Off the top of my head, I don't think you can, i.e. I do not think that the feature is implemented in the toolkit since the toolkit aims to provide a generic interface to CVI for database connectivity.
I am curious however, why you want to do this. The very reason for using a database is to get access to the same dataset from multiple connections. Maybe you should use a file instead of a database of you want locked access.
01-15-2017 10:08 AM
Thanks for the reply; however, it was done in a local file for locking.
It's just a requirement that I need to do.
I'm trying to use DBBeginTran() and DBCommit(); but still trying it out.
For example, multiple users must be able to obtain, let's say a counter, from the SQL db; however, users must not have a duplicate of the counter.
Steps:
1. user1 gets counter from DB (counter = 1)
2. user1 increments counter++
3. user2 connects and gets counter from DB (counter = 1)
4. user1 updates counter in DB to counter = 2
5. user2 increments counter++
6. user2 updates counter in DB but realize counter read (step3) does not match...
I want to avoid this situation because user1 and user2 will have a counter of 1, where it's supposed to be user1 have counter = 1 and user2 have counter = 2, etc.