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

x
?
Solved

Opening an ADODB connection in exclusive mode

Posted on 2000-04-13
12
Medium Priority
?
1,836 Views
Last Modified: 2012-08-13
I need to open the database in exclusive mode so that I ensure consistent data.

I'm using an ADO connection to connect to the database.
if i give a con.mode=adModeShareExclusive just before opening the connection, i get an error.

Are there any restrictions in using this mode?

any clues as to why this happens?

0
Comment
Question by:vidyas
[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
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2712079
What Provider/ODBC Driver do you use?
What database do you want to query?
What Error do you get?
Please post of your code!
0
 
LVL 1

Expert Comment

by:detiege
ID: 2712133
Dim cnn1 As ADODB.Connection
   Dim rstTitles As ADODB.Recordset
   Dim strCnn As String

   ' Assign connection string to variable.
   strCnn = "Provider=sqloledb;" & _
      "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "

   ' Open connection and titles table.
   Set cnn1 = New ADODB.Connection
   cnn1.Mode = adModeShareExclusive
   cnn1.IsolationLevel = adXactIsolated
   cnn1.Open strCnn
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2713440
Deteige:
Very nice answer.. IF the questioner is using SQL as their server. As not all Provider's are created equal.. How do you know that SQL is the questioner's server of choice?.

As I find AngelIII's comment most germaine to the question, please change your answer to a comment.. until we know more.. <smile>.
0
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.

 

Author Comment

by:vidyas
ID: 2714712
The provider is the default: Microsoft OLE DB Provider

I want to query an Access database.

Code::

Public con As New ADODB.Connection '//The sole connection object
Public rs As New ADODB.Recordset
Public connectString As String

Public Function Initialize() As Boolean
'//This function initializes TracerInitVariables
'//when the application is invoked
'//for the first time

If Not TracerInit.IsDebugMode Then On Error GoTo errHandler

'//-connection set up
connectString = "DSN=Tracer"
con.Mode = adModeShareDenyWrite 'adModeShareExclusive
con.Open connectString
rs.CursorLocation = adUseClient
Initialize = True
Exit Function

errHandler:
    Call TracerError.ShowErr(Err)
    Initialize = False  '//-signal init failure
End Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error returned::

The flow jumps to the label errHandler and displays a message "Errors occured".

and the return value of the function is false.
0
 
LVL 1

Expert Comment

by:detiege
ID: 2714946
detiege changed the proposed answer to a comment
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2714948
Unfortunately, you didn't tell us which version of Access, but i got the same error for A97 and A2K, so i think (need to look up doc) that this mode is not supported by ODBC driver for Access.

In the options of the ODBC DSN however i detected in the advanced part some interesting checkboxes which may resolve your problem...

FYI:
I suggest that you don't declare your variables AS NEW, as this is a performance break.
Instead declare AS and issue you SET = NEW statements in the Initialize Sub
0
 

Author Comment

by:vidyas
ID: 2715038
oops.. forgot to mention the version.
it is Access 97.

pardon me, I couldn't find any checkboxes. could you please guide me where to find these options?

reg your suggestion:: thanks for the info and I'm gonna remove the 'new' from the declaration as per your suggestion, but i'd still like to know how this could affect the performance??
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 2715054
If you declare objects as new, on every line you use the object, VB will add code during compilation to check if the object is nothing and create the object if necessary.
I found the checkboxes when
*) i openend the ODBC applet in Control Panel
*) selected the DSN Trace
*) issue Configure
*) clicked on options button (these properties can also be found in the advanced screen)


0
 

Author Comment

by:vidyas
ID: 2715279
guess what?? I don't get any kind of checkboxes.

What is the OS you are working on?

I'm on Win NT
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2715312
NT 4 SP 5 Access 97 MDAC 2.1
0
 

Author Comment

by:vidyas
ID: 2715468
does this mean that i cannot open an access databse in exclusive mode?

if i can do this somehow, please let me know.
0
 

Author Comment

by:vidyas
ID: 2715550
Thanks angelIII

I marked the database to be opened in Exclusive mode through control panel.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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