asp.net and access database locking?

B

Brian K. Williams

I have run across this.. In my case it was because the Access database was
being used by another network user directly from Access.

-Brian
 
S

Scott M.

If you have made your connection via the Server Explorer window in VS .NET,
then the .ldb file will remain regardless of the state of the connection
object because VS .NET maintains a pathway to the DB.

Even if you didn't use the Server Explorer window to create the connection,
the .ldb file remains because ADO .NET uses connection pooling by default.
So, even if you close the connection explicitly, the connection will still
exist in the pool. To disable connection pooling add "OLE DB Services=-4"
to your connection string.
 
J

Jos

amessimon said:
Hi

Having problems using an access database where i seem to create a
locked file on making a connection.

I think ive covered all the basics like properly closing the
connection etc....
Are there any probs with setting connections in web.config that might
create this problem?

I've included a simplified version of the code in question below.

In my local test enviroment i can restart IIS to remove the lock, i
cant do this live as i use shared hosting evironment and have no
control over the box.
Anyone ever come across anything like this?

Thanks in advance
amessimon



'##########################################

'connection string in web.config
Dim strConnection as string =
ConfigurationSettings.AppSettings("ConnectionString")
Dim strSQL as string = SQL statement...............
Dim objConnection as New OledbConnection(strConnection)
Dim objCommand as New OledbCommand(strSQL,objConnection)
Dim objDataReader as OledbDataReader
objConnection.Open()
objDataReader = objCommand.ExecuteReader()

Do While objDataReader.Read() = true
'etc.................
Loop

objDataReader.close()
objConnection.close()

'##########################################

For Access connections, I always use an exception block.
If anything goes wrong, you can make sure that the connection
doesn't stay open. If it does stay open, you'll have to kill the
ASPNET process or even restart the server to get access again.

Dim objConnection As New OleDbConnection(strConnection)
Try
' do your stuff here
Finally
objConnection.Close()
End Try
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

Try adding objConnection.Dispose() after the whole thing.

Access will always create a lock file, so in and out ASAP is the best
option. The dispose should mark the conn as complete and release the lock.

Also check your conn string. You can lock things up unnecessarily with the
wrong conn string.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

IN the connstring add mode=16; (in web.config). I have not seen this, but I
will run with it (ignorance is bliss ;->)

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
D

Duffaukid

No one said it was your clock. The post was a reply to the OP.

No it wasn't.


Saber said:
That's right but it is not my clock, its "amessimon" clock, I'll email him.
Scott M. said:
Why should we have to hide this post. Why not just fix the clock?

"Saber" <saber[--AT--]maghalat.com> wrote in message

Have you tried setting your clock to the correct month?


It is fun! Outlook Express has not an option to "hide" this post?!
 
S

Scott M.

Um, yes it was. "msnews.microsoft.com" posted a direct reply to the OP:
"Have you tried setting your clock to the correct month?" and this is what
I'm talking about.




Duffaukid said:
No one said it was your clock. The post was a reply to the OP.

No it wasn't.


Saber said:
That's right but it is not my clock, its "amessimon" clock, I'll email him.
Why should we have to hide this post. Why not just fix the clock?

"Saber" <saber[--AT--]maghalat.com> wrote in message

Have you tried setting your clock to the correct month?


It is fun! Outlook Express has not an option to "hide" this post?!
 
A

amessimon

Hi

Having problems using an access database where i seem to create a locked
file on making a connection.

I think ive covered all the basics like properly closing the connection
etc....
Are there any probs with setting connections in web.config that might create
this problem?

I've included a simplified version of the code in question below.

In my local test enviroment i can restart IIS to remove the lock, i cant do
this live as i use shared hosting evironment and have no control over the
box.
Anyone ever come across anything like this?

Thanks in advance
amessimon



'##########################################

'connection string in web.config
Dim strConnection as string =
ConfigurationSettings.AppSettings("ConnectionString")
Dim strSQL as string = SQL statement...............
Dim objConnection as New OledbConnection(strConnection)
Dim objCommand as New OledbCommand(strSQL,objConnection)
Dim objDataReader as OledbDataReader
objConnection.Open()
objDataReader = objCommand.ExecuteReader()

Do While objDataReader.Read() = true
'etc.................
Loop

objDataReader.close()
objConnection.close()

'##########################################
 
A

amessimon

Probably a stupid question....but this is difficult to test as i have to
either copy and rename the database or restart IIS everytime i test
this...so i'll ask it.

Is this another node or an attribute. Where do i add this?
Also what does this mode setting do exactly, i'm having trouble finding
references online.

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top