Database connection - not valid path

G

Guest

Hi

I'm trying to connect to my database which I'm holding on
the local server (I've created a virtual directory).

If I use the following in web.config:
<add key="ConnectionString"
value="Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=/loctest/locdb.mdb" />

then I get the following error message:
'C:\loctest\locdb.mdb' is not a valid path. Make sure that
the path name is spelled correctly and that you are
connected to the server on which the file resides.

I've tried a number of variations for the data source path
but I can't get it to look at the correct directory
(loctest) on the server.

Can anyone tell me what my path should be?

Thanks in advance.
 
M

Miha Markic

Hi rona,

I presume you are running an asp.net application.
Check if user account aspnet (the account under which your asp.net
application is running) has enough privileges to get to the mdb file
 
M

Miha Markic

The asp.net account has full access to the source on the
c:drive and the virtual directory and database have read
and write properties.

If I set the data source to c:\databasedirectory\locdb.mdb
then it's fine and I can connect ok but I want to access
it from my local server.

Hmmm. What exactly does mean "access it from my local server"?
What is the difference from c:\databasedirectory and c:\loctest?
 
J

Jonel Rienton

Hi

I'm trying to connect to my database which I'm holding on
the local server (I've created a virtual directory).

If I use the following in web.config:
<add key="ConnectionString"
value="Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=/loctest/locdb.mdb" />

then I get the following error message:
'C:\loctest\locdb.mdb' is not a valid path. Make sure that
the path name is spelled correctly and that you are
connected to the server on which the file resides.

I've tried a number of variations for the data source path
but I can't get it to look at the correct directory
(loctest) on the server.

Can anyone tell me what my path should be?

Thanks in advance.

Rona,

Hi, i don't think you can create your connection string like if you're
running an ASP.Net application and using Microsoft.JET.OLEDB.4.0(at
least). One work around is that you have to define the connection string
inside your code. See my example below:

One of the drawback i can think of is your connection string is
hardcoded in your code.

namespace AccessDB.Data {
public class DbManager {
public DbManager() {
}//ctor

public bool TestConnection() {
OleDbConnection cnn = CreateConnection();
bool isOk = true;
try {
cnn.Open();
} catch (Exception e) {
isOk = false;
Business.LogManager.LogEvent(e.Message);
} finally {
cnn.Close();
}

return isOk;
}//TestConnection

private OleDbConnection CreateConnection() {
string cnnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
HttpContext.Current.Server.MapPath("mydb.mdb");
OleDbConnection cnn = new OleDbConnection(cnnstr);
return new OleDbConnection(cnn);
}//CreateConnection
}
}

regards,
Jonel
 

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