Connect to Access via Remote Object

L

Looch

All,

I have a remotable object hosted in IIS and one of the methods
connects to an Access db on a different machine. I can't seem to
connect to the access db.

I thought there may have been a permissions issue so I copied the
Access db to the physical directory that the virtual dir is pointed to
and still it tells me that the file path is not valid.

I did something similar in an asp.net web service method and had to
use Server.MapPath(".")... for the Acess db directory. Is there
something similar I can use in a DLL method that is hosted in a
virtual directory?

Thanks for any suggestions.
 
N

Nicholas Paldino [.NET/C# MVP]

Looch,

Well, you can use the static Current method on the HttpContext class to
get the current HttpContext. From the HttpContext you can get the request,
response, server, etc, etc. That should give you access to MapPath.
 
L

Looch

Thanks Nick,

Unless I'm misunderstanding, I don't need to use the MapPath mentioned
above. I added that because it seems like I'm in a similar issue - the
web service I was using needed to access an Access db - the only way I
was able to do that was to have the db in the MapPath dir for that web
service. (There's probably other ways but this happened to work)

Should I be able to, in the context of a remotable object hosted in
IIS, connect to a remote db through this hosted object?

If so, would the db need to be on the local machine, in the virtual
dir, etc? This seems like an easy thing to do, yet I'm having real
diffculty.

Thanks again.
 
N

Nicholas Paldino [.NET/C# MVP]

Looch,

You should be able to access the db wherever it is, as long as the
machine has a way of accessing it, and the user that the service is running
under has the rights to it.

If you are not impersonating the user that is executing the method, then
you need to make sure that the user that the hosting environment is running
under has access to where the database is.

Otherwise, if you are impersonating the user, then you have to make sure
that the user has access to the file that you are trying to access.
 
S

sloan

I would first hardcode the complete mdb filename into the code (or put the
hardpath into a config file)..
and get that working.

The access error messages are pretty flakey sometimes.

My guess is that you are correct with permissions.

If I recall correctly, the userAccount needs to be able to READ/WRITE the
..mdb file (duh) ..AND the folder needs WRITE/READ as well, because of that
..ldb file. Ah yes, the memories.... the LDB file can screw you up as well.

But I'm thinking back to a long time ago.

Make sure you know which userAccount is being used. ( as stated
previously ).

You might use the crappy TEMP only code:

private string FindIIdentity()

{

try

{

//'Dim user As WindowsPrincipal =
CType(System.Threading.Thread.CurrentPrincipal, WindowsPrincipal)

//'Dim ident As IIdentity = user.Identity

string returnValue = string.Empty;



WindowsIdentity ident = WindowsIdentity.GetCurrent();

returnValue = ident.Name;

try

{

returnValue += " on " + System.Environment.MachineName;

}

catch (Exception ex)

{

}

return returnValue;

}



catch (Exception ex)

{

return "Error Finding Identity";

}

}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


You hsould be able to access the DB using UNC , like
\\dbserver\path\to\db.dbf
 

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

Top