How to access the database via a virtual folder that points to remote access

I have a problem accessing a database that lives on a remote server.

I have an ASP.NET 2.0 web page that is trying to connect to a database.
The database is accessed through a virtual folder (which I set up in IIS).
The virtual folder points to the remote share that contains the database.

The virtual folder (in the root directory of web applications) points to a share on a remote server under the UNC path:

\\databaseServerName\databaseFolder$\ 

      

The virtual folder is set to "read" and "view" permissions to "true".

I am storing the connection string in the "appSettings" section in the web.config file:

<add key="conStrVirtual" value="Provider=Microsoft.Jet.OleDb.4.0;Data Source=http://webAppServerName/virtualFolderName/databaseName.MDB;Jet OLEDB:Database Password=dumbPassword;"/>

      

The connection object is declared in my .aspx page:

Dim objConnVirtual As New OleDbConnection(ConfigurationManager.AppSettings("conStrVirtual"))

      

Here's the code that tries to use the connection object:

Public Sub Test()
    If objConnVirtual.State <> ConnectionState.Open Then
        objConnVirtual.Open()
    End If
    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM TableName", objConnVirtual)
    objDR = cmd.ExecuteReader()
    If objDR.Read() Then
        response.write("Shazaam! Data shows up here")
    End If
    objDR.Close()
    objConnVirtual.Close()
End Sub

      

When I run the above code, I get the following error (on this line of code "objConnVirtual.Open ()":
Exception Details: System.Data.OleDb.OleDbException: Invalid file name.

I checked the database name and it is correct (even copied / pasted it to make sure)

If I put the Data Source section of the connection string in the address bar of my browser, I can successfully view the contents of that resource on the remote server.

Not sure if this is a permissions or code issue.
I searched this shit out of this but couldn't find a solution.

Any help is greatly appreciated.

0


source to share


5 answers


UPDATE

First of all, thanks to everyone who submitted the answers.



However, we did not use the "connect to a remote database via a virtual folder" method because the complexity of the permissions required to get it working was causing us more problems than it was worth. We put the UNC path back into the connection string, which might not be the best way to do it, but it works for us.

0


source


When accessing a remote access MDB database, you need to provide a UNC path, for example \\ remoteMachine \ Share \ test.mdb.

Make sure the application pool ID has the correct permissions to connect to the remote resource. By default in IIS 6, you are running the Network Service account, which by default does not have access to the remote resource.



The best way is to let AppPool run with a dedicated user of the service.

+1


source


What is the account used on your server when your web application tries to read the db file? Regardless of this user account, it must have read permissions on this folder / file. In IIS6 you can configure the virtual folder to use any user account ... under the Directory Security tab there is an Edit button under Authentication and Access Control.

It seems likely that your error message is a generic error message and the permissions issue is your real problem.

+1


source


make sure the two servers have internal access to each other and also include the ip and port of the db server in the connection string.

0


source


Refresh

I should also mention what works on my computer (but does not boot once before the production window) if I declare the connection string in the "appSettings" section of the web.config file:

<add key="conStrVirtual" value="Provider=Microsoft.Jet.OleDb.4.0;Data Source=\\databaseServerName\databaseFolder$\databaseName.MDB;Jet OLEDB:Database Password=dumbPassword;"/>

      

This leads me to think that it might be a problem when you need to use domain credentials other than the local IUSER account.

0


source







All Articles