473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Open MS Access Exclusive

I am creating a new MS Access DB in code, which works fine. I then try to
open it & set a password. I keep getting an error that the DB is already open
by my machine's Admin account. In reality it is not actually open.
Here is a look at my code for creating & then setting the Password.

Dim ADOXcat As New ADOX.Catalog
sCreateString = "Provider=" & Provider & ";Data Source=" & DatabaseFullPath

Try
ADOXcat.Create(sCreateString)
bAns = True
Catch Excep As System.Runtime.InteropServices.COMException
bAns = False
MessageBox.Show("Could not create Database. " & Excep.ToString,
"Create DataBase", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return bAns
Exit Function
Finally
ADOXcat = Nothing
End Try
Up to this point things work fine, the DB is created in the folder specified.
Here is where I have the problem

Dim NewTabConn As New System.Data.OleDb.OleDbConnection
sCreateString = "Provider=" & Provider & ";Data Source=" & DatabaseFullPath
'& "; Jet OLEDB:Mode=Share Exclusive"
(I redefine my connection string to open the db exclusively)

NewTabConn = New OleDbConnection(sCreateString)
Dim NewDBPassCmd As OleDbCommand = New OleDbCommand

NewDBPassCmd.Connection = NewTabConn
NewDBPassCmd.CommandText = "ALTER DATABASE PASSWORD CHURCH NULL"
NewTabConn.Close()
Try
NewTabConn.Open() <<<<--This is where the problem occurs
NewDBPassCmd.ExecuteNonQuery()
NewTabConn.Close()
Catch ex As OleDbException
MessageBox.Show("Error: " & ex.ErrorCode & ex.Message, "Error",
MessageBoxButtons.OK)
NewTabConn.Close()
Finally
NewDBPassCmd.Dispose()
End Try

The error I get is this:
You attempted to open a database that is already opened exclusively by user
'Admin' on machine 'GHUSTIS'. Try again when the database is available.

So somewhere between the creation of the db & altering it i need to close it
completely, but is isn't really opened. How can i do this?

As a note: the sCreateString variable is created using other varialbe to set
the db location to use jet4.0

Thanks
Gary
Jul 31 '07 #1
6 4710
On Tue, 31 Jul 2007 14:50:01 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:

¤ I am creating a new MS Access DB in code, which works fine. I then try to
¤ open it & set a password. I keep getting an error that the DB is already open
¤ by my machine's Admin account. In reality it is not actually open.
¤ Here is a look at my code for creating & then setting the Password.
¤
¤ Dim ADOXcat As New ADOX.Catalog
¤ sCreateString = "Provider=" & Provider & ";Data Source=" & DatabaseFullPath
¤
¤ Try
¤ ADOXcat.Create(sCreateString)
¤ bAns = True
¤ Catch Excep As System.Runtime.InteropServices.COMException
¤ bAns = False
¤ MessageBox.Show("Could not create Database. " & Excep.ToString,
¤ "Create DataBase", MessageBoxButtons.OK, MessageBoxIcon.Error)
¤ Return bAns
¤ Exit Function
¤ Finally
¤ ADOXcat = Nothing
¤ End Try
¤ Up to this point things work fine, the DB is created in the folder specified.
¤ Here is where I have the problem
¤
¤ Dim NewTabConn As New System.Data.OleDb.OleDbConnection
¤ sCreateString = "Provider=" & Provider & ";Data Source=" & DatabaseFullPath
¤ '& "; Jet OLEDB:Mode=Share Exclusive"
¤ (I redefine my connection string to open the db exclusively)
¤
¤ NewTabConn = New OleDbConnection(sCreateString)
¤ Dim NewDBPassCmd As OleDbCommand = New OleDbCommand
¤
¤ NewDBPassCmd.Connection = NewTabConn
¤ NewDBPassCmd.CommandText = "ALTER DATABASE PASSWORD CHURCH NULL"
¤ NewTabConn.Close()
¤ Try
¤ NewTabConn.Open() <<<<--This is where the problem occurs
¤ NewDBPassCmd.ExecuteNonQuery()
¤ NewTabConn.Close()
¤ Catch ex As OleDbException
¤ MessageBox.Show("Error: " & ex.ErrorCode & ex.Message, "Error",
¤ MessageBoxButtons.OK)
¤ NewTabConn.Close()
¤ Finally
¤ NewDBPassCmd.Dispose()
¤ End Try
¤
¤ The error I get is this:
¤ You attempted to open a database that is already opened exclusively by user
¤ 'Admin' on machine 'GHUSTIS'. Try again when the database is available.
¤
¤ So somewhere between the creation of the db & altering it i need to close it
¤ completely, but is isn't really opened. How can i do this?
¤
¤ As a note: the sCreateString variable is created using other varialbe to set
¤ the db location to use jet4.0
¤
¤ Thanks
¤ Gary
¤

Have you tried closing the database connection through ADOX? It would appear that ADOX is keeping
its connection open.
Paul
~~~~
Microsoft MVP (Visual Basic)
Aug 1 '07 #2


"Paul Clement" wrote:
On Tue, 31 Jul 2007 14:50:01 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:

¤ I am creating a new MS Access DB in code, which works fine. I then try to
¤ open it & set a password. I keep getting an error that the DB is already open
¤ by my machine's Admin account. In reality it is not actually open.
¤ Here is a look at my code for creating & then setting the Password.
¤
¤ Dim ADOXcat As New ADOX.Catalog
¤ sCreateString = "Provider=" & Provider & ";Data Source=" & DatabaseFullPath
¤
¤ Try
¤ ADOXcat.Create(sCreateString)
¤ bAns = True
¤ Catch Excep As System.Runtime.InteropServices.COMException
¤ bAns = False
¤ MessageBox.Show("Could not create Database. " & Excep.ToString,
¤ "Create DataBase", MessageBoxButtons.OK, MessageBoxIcon.Error)
¤ Return bAns
¤ Exit Function
¤ Finally
¤ ADOXcat = Nothing
¤ End Try
¤ Up to this point things work fine, the DB is created in the folder specified.
¤ Here is where I have the problem
¤
¤ Dim NewTabConn As New System.Data.OleDb.OleDbConnection
¤ sCreateString = "Provider=" & Provider & ";Data Source=" & DatabaseFullPath
¤ '& "; Jet OLEDB:Mode=Share Exclusive"
¤ (I redefine my connection string to open the db exclusively)
¤
¤ NewTabConn = New OleDbConnection(sCreateString)
¤ Dim NewDBPassCmd As OleDbCommand = New OleDbCommand
¤
¤ NewDBPassCmd.Connection = NewTabConn
¤ NewDBPassCmd.CommandText = "ALTER DATABASE PASSWORD CHURCH NULL"
¤ NewTabConn.Close()
¤ Try
¤ NewTabConn.Open() <<<<--This is where the problem occurs
¤ NewDBPassCmd.ExecuteNonQuery()
¤ NewTabConn.Close()
¤ Catch ex As OleDbException
¤ MessageBox.Show("Error: " & ex.ErrorCode & ex.Message, "Error",
¤ MessageBoxButtons.OK)
¤ NewTabConn.Close()
¤ Finally
¤ NewDBPassCmd.Dispose()
¤ End Try
¤
¤ The error I get is this:
¤ You attempted to open a database that is already opened exclusively by user
¤ 'Admin' on machine 'GHUSTIS'. Try again when the database is available.
¤
¤ So somewhere between the creation of the db & altering it i need to close it
¤ completely, but is isn't really opened. How can i do this?
¤
¤ As a note: the sCreateString variable is created using other varialbe to set
¤ the db location to use jet4.0
¤
¤ Thanks
¤ Gary
¤

Have you tried closing the database connection through ADOX? It would appear that ADOX is keeping
its connection open.
Paul
~~~~
Microsoft MVP (Visual Basic)
Paul,
I would agree that ADOX is keeping the connection open, However ADOX does
not seem to have a connection open() or close() arguement. When the code
calls ADOXcat.Create(sCreateString), ADOX opens its own connection using the
connection string provided. I figured that by setting the ADOXcat = nothing
that i would kill the connection, but no luck.
If you know of a way to close the connection please let me know.
Thanks
Gary
>
Aug 1 '07 #3
On Wed, 1 Aug 2007 13:30:03 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:
¤ Paul,
¤ I would agree that ADOX is keeping the connection open, However ADOX does
¤ not seem to have a connection open() or close() arguement. When the code
¤ calls ADOXcat.Create(sCreateString), ADOX opens its own connection using the
¤ connection string provided. I figured that by setting the ADOXcat = nothing
¤ that i would kill the connection, but no luck.
¤ If you know of a way to close the connection please let me know.
¤ Thanks
¤ Gary
¤ >

Have you tried ADOXcat.ActiveConnection.Close?
Paul
~~~~
Microsoft MVP (Visual Basic)
Aug 2 '07 #4


"Paul Clement" wrote:
On Wed, 1 Aug 2007 13:30:03 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:
¤ Paul,
¤ I would agree that ADOX is keeping the connection open, However ADOX does
¤ not seem to have a connection open() or close() arguement. When the code
¤ calls ADOXcat.Create(sCreateString), ADOX opens its own connection using the
¤ connection string provided. I figured that by setting the ADOXcat = nothing
¤ that i would kill the connection, but no luck.
¤ If you know of a way to close the connection please let me know.
¤ Thanks
¤ Gary
¤ >

Have you tried ADOXcat.ActiveConnection.Close?
Paul
~~~~
Microsoft MVP (Visual Basic)
Paul,
Yes I have, however VS.Net2005 throws an error. Activeconnection.Close is
not a valid method. The actual error i get is "Option Strict On Disallows
late binding". Also the intelisense does not expose 'close' as a method for
Activeconnection, or any other ADOX method.
It's hard for me to believe that I am the only one who as encountered this
problem. Someone else must have experienced this & solved it.
I am also willing to create the database in another way (other than ADOX) if
it will give me the ability to create it and set a password. But I haven't
found that solution either.
Thanks
Gary
>
Aug 2 '07 #5
On Thu, 2 Aug 2007 09:26:00 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:

¤
¤
¤ "Paul Clement" wrote:
¤
¤ On Wed, 1 Aug 2007 13:30:03 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:
¤ >
¤ >
¤ ¤ Paul,
¤ ¤ I would agree that ADOX is keeping the connection open, However ADOX does
¤ ¤ not seem to have a connection open() or close() arguement. When the code
¤ ¤ calls ADOXcat.Create(sCreateString), ADOX opens its own connection using the
¤ ¤ connection string provided. I figured that by setting the ADOXcat = nothing
¤ ¤ that i would kill the connection, but no luck.
¤ ¤ If you know of a way to close the connection please let me know.
¤ ¤ Thanks
¤ ¤ Gary
¤ ¤ >
¤ >
¤ Have you tried ADOXcat.ActiveConnection.Close?
¤ >
¤ >
¤ Paul
¤ ~~~~
¤ Microsoft MVP (Visual Basic)
¤
¤ Paul,
¤ Yes I have, however VS.Net2005 throws an error. Activeconnection.Close is
¤ not a valid method. The actual error i get is "Option Strict On Disallows
¤ late binding". Also the intelisense does not expose 'close' as a method for
¤ Activeconnection, or any other ADOX method.
¤ It's hard for me to believe that I am the only one who as encountered this
¤ problem. Someone else must have experienced this & solved it.
¤ I am also willing to create the database in another way (other than ADOX) if
¤ it will give me the ability to create it and set a password. But I haven't
¤ found that solution either.
¤ Thanks
¤ Gary
¤ >

Try the following:

CType(ADOXcat.ActiveConnection, ADODB.Connection).Close()
Paul
~~~~
Microsoft MVP (Visual Basic)
Aug 3 '07 #6


"Paul Clement" wrote:
On Thu, 2 Aug 2007 09:26:00 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:

¤
¤
¤ "Paul Clement" wrote:
¤
¤ On Wed, 1 Aug 2007 13:30:03 -0700, G Hustis <GH*****@discussions.microsoft.comwrote:
¤ >
¤ >
¤ ¤ Paul,
¤ ¤ I would agree that ADOX is keeping the connection open, However ADOX does
¤ ¤ not seem to have a connection open() or close() arguement. When the code
¤ ¤ calls ADOXcat.Create(sCreateString), ADOX opens its own connection using the
¤ ¤ connection string provided. I figured that by setting the ADOXcat = nothing
¤ ¤ that i would kill the connection, but no luck.
¤ ¤ If you know of a way to close the connection please let me know.
¤ ¤ Thanks
¤ ¤ Gary
¤ ¤ >
¤ >
¤ Have you tried ADOXcat.ActiveConnection.Close?
¤ >
¤ >
¤ Paul
¤ ~~~~
¤ Microsoft MVP (Visual Basic)
¤
¤ Paul,
¤ Yes I have, however VS.Net2005 throws an error. Activeconnection.Close is
¤ not a valid method. The actual error i get is "Option Strict On Disallows
¤ late binding". Also the intelisense does not expose 'close' as a method for
¤ Activeconnection, or any other ADOX method.
¤ It's hard for me to believe that I am the only one who as encountered this
¤ problem. Someone else must have experienced this & solved it.
¤ I am also willing to create the database in another way (other than ADOX) if
¤ it will give me the ability to create it and set a password. But I haven't
¤ found that solution either.
¤ Thanks
¤ Gary
¤ >

Try the following:

CType(ADOXcat.ActiveConnection, ADODB.Connection).Close()
Paul
~~~~
Microsoft MVP (Visual Basic)
Paul,
Thanks for the suggestion, however it does not work. VB gives me an error on
the ADO.Connection portion & says 'Connection is ambiguous in the namespace
ADODB. I also tried a few other renditions of this and could not find a
solution.
I tried to follow what the MSDN atricle says: 'Setting the ActiveConnection
property to Nothing should close the connection to the catalog', which i have
done and it still does not work.
http://msdn2.microsoft.com/en-us/library/ms681562.aspx
Gary

>
Aug 3 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill | last post by:
I have three databases running, all with a slightly different function: 1) Shared Database where data entry is done 2) Data Inventory where information from the Shared Database is loaded to...
3
by: wandali | last post by:
When I want to edit a MS Database, I have to run the following command: "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "\\Server\Directory\File.mdb" /wrkgrp...
0
by: Wayne | last post by:
Can someone please help with this problem. When referring to opening a database in Exclusive mode the Access 2003 help says: "Under Default open mode, do one of the following: If you want others...
2
by: Javier Gomez | last post by:
How to open a linked table in exclusive mode from a FORM in DAO ??? (but,...... please I need it in DAO.) Thank you ! Javier Gomez
2
by: Mat | last post by:
Or how to check if it's open in exclusive mode...? Thx
1
by: buclas | last post by:
Hi, I need to link a mdb file and make sure it opens in a non-exclusive mode. I looked for a similar post but none was answered. I know there is a specific param to add to the command line to...
0
by: Salad | last post by:
A97. Split database. Frontend DB1.MDB. Backend DB1BE.MDB. Tables are linked between DB1 and DB2. From my testing, if I open DB1 exclusively using /excl the backend DB1BE is not opened...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
14
by: SimeonD | last post by:
Hi I have an access database called Sales.Mdb In vb.net 2005, I'd like to open it. Which I can do. What I can't figure out is how to figure out if Sales.Mdb is open already. If so, I want to open...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.