Link to home
Start Free TrialLog in
Avatar of liorsolomon
liorsolomon

asked on

Problem:"It is already opened exclusively by another user, or you need permission to view its data"

Hi,
I'm a newbie to asp.net, and I'm facing a very anoying problem.
All I'm trying to do is connect to an access db and query some tables
I'm getting this error which doesn't makes sense to me:

System.Data.OleDb.OleDbException: The Microsoft Jet database engine cannot open the file 'D:\mypath\db.mdb'. It is already opened exclusively by another user, or you need permission to view its data. at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open() at UserMail.Create_Mail_Display() in ....

I'm using the same code for different scripts on the site and I don't get this message.
So obviously it can't be some script opening it exclusivly.
I have a feeling its more of a IIS setup issue.

Could someone help?
Avatar of liorsolomon
liorsolomon

ASKER

I forgot to add the code:

Private Conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/vhosts/shaytubaly.org.il/httpdocs/db.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False")
Private Conn2 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/vhosts/shaytubaly.org.il/httpdocs/db.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False")

      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Create_Mail_Display()
      End Sub

      Sub Create_Mail_Display()
            Dim strsql As String = "Select * From MailList M ORDER BY M.Ordered"
            Dim ObjCmd As New OleDb.OleDbCommand(strsql, Conn)
            Dim SchdlCmd As New OleDb.OleDbCommand
            Dim objReader As OleDb.OleDbDataReader
            Dim ScheduleReader As OleDb.OleDbDataReader
            Try
                  ObjCmd.Connection.Open()
                  objReader = ObjCmd.ExecuteReader()
            Catch ex As Exception
                  Response.Write(ex.ToString)
                  Response.End
            End Try

It throws the exception and steps out

Thanks
Avatar of CyrexCore2k
You might get a better response if you post this in the ASP.Net section.

I would try to help you but I haven't dealt much withe ASP.Net.
Thanks
:)
Did you have the database open viewing the same table at the time you made the request - Access quite often seems to lock it open if I start Access first then browse it with a page. To get round this I setup queries to match the table and only open those in access and use the same ones in the asp.net code calls.

S.
The funny thing is that other scripts that uses the same connection string :
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/vhosts/shaytubaly.org.il/httpdocs/db.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False" are succeding to query the mdb file.
But this specific aspx file doesn't.
Could it be that asp.net has different permission vs asp permission to files at the virtual directory? because I do succeed to connect to the mdb while using an asp file.
Check the security permissions on the folder which contains the database file. IUSER_servername (where "servername" is the name of your server) needs write permissions in that folder in order to create a temp file there.
As i said before,
If that was the problem, I couldn't read the data in any way.
There are few scripts that succeeds to read from that file. so it can't be the permissions of the file or directory.
If the permissions are not correct, queries that do not require a temp file would execute without errors. Other queries would cause the above error. Believe me, I've tripped over this error often enough. That's the first thing I check -- make sure that IUSER_servername has full control of the folder containing the mdb file.
ASKER CERTIFIED SOLUTION
Avatar of walkerke
walkerke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I usually get that error when i have the table open in design view then try to use the table in my scripts.
Hi everyone,
I afraid I quite confused everyone with my problem
a deeper investigation discovered that the problem is related to the fact that only asp.net script can't access the db.
If i try any asp files to connect to the db it works perfectly, but if I try .net i get the error.
Is there any permissions issues regarding .net framework accessing access files?

Thanks
Yes - the access drivers use what is known as unmanageble code ... and this could be your problem.

Please see one of my previous answers
https://www.experts-exchange.com/questions/21877457/Error-when-trying-to-connect-to-Microsoft-Access-database-on-hosting-server.html

It .net 2.0 there is a setting to allow DB access to be overriden in terms of the unmanagable code ... kinda like don't run unless its for database purposes... Altho I can't remember where the setting is - and this assumes you are running 2.0
Hey liorsolomon you should seriously consider switching to MySQL. If you've been doing this awhile switching to a full fledged DB engine is a good idea.