Unable to Write to Access DB based on Connection String

J

John W

Hello. I am experiencing a rather odd issue. I am able to both read and
write data to an Access database when my connection string is as follows:

cn = "@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\nwind.mdb;Persist
Security Info=True"

However, I am only able to read the data when the database is added to the
project and the connection string is as follows:

cn =
System.Configuration.ConfigurationManager.ConnectionStrings["WindowsFormsApplication1.Properties.Settings.Database1ConnectionString"].ConnectionString;

Why am I able to read the data using both connections but only able to write
when I use the physical path to the file?

It seems that as soon as I add the database to the project I am unable to
write to it.

Any thoughts?
 
J

John W

Forgot to mention. The app.config contains the following info for the
connection string:

<add
name="WindowsFormsApplication1.Properties.Settings.nwindConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\nwind.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />

Very strange that I can read the data no problem using eith of the
connections but cannot write when using the connection from app.config
(database added to project).
 
F

Family Tree Mike

Forgot to mention. The app.config contains the following info for the
connection string:

<add
name="WindowsFormsApplication1.Properties.Settings.nwindConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\nwind.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />

Very strange that I can read the data no problem using eith of the
connections but cannot write when using the connection from app.config
(database added to project).

John W said:
Hello. I am experiencing a rather odd issue. I am able to both read
and write data to an Access database when my connection string is as
follows:

cn = "@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\nwind.mdb;Persist Security Info=True"

However, I am only able to read the data when the database is added to
the project and the connection string is as follows:

cn =
System.Configuration.ConfigurationManager.ConnectionStrings["WindowsFormsApplication1.Properties.Settings.Database1ConnectionString"].ConnectionString;


Why am I able to read the data using both connections but only able to
write when I use the physical path to the file?

It seems that as soon as I add the database to the project I am unable
to write to it.

Any thoughts?

You probably don't have write access to the file in the installation
path, such as c:\program files\my app\App_Data\nwind.mdb. Most systems
lock down c:\program files and below. You likely do have write access
to a file in the other location.
 
J

John W

Thanks. Was considering that. I'm using ClickOnce technology to deploy the
application and corresponding files. I figure I have to add the Access db
to the project in order for it to get included with the ClickOnce package.
Only problem then is that I cant write to it. I need somehow to include the
Access db in the package and have it written to a different directory. Just
cant figure out how to do that.

Family Tree Mike said:
Forgot to mention. The app.config contains the following info for the
connection string:

<add
name="WindowsFormsApplication1.Properties.Settings.nwindConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\nwind.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />

Very strange that I can read the data no problem using eith of the
connections but cannot write when using the connection from app.config
(database added to project).

John W said:
Hello. I am experiencing a rather odd issue. I am able to both read
and write data to an Access database when my connection string is as
follows:

cn = "@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\nwind.mdb;Persist Security Info=True"

However, I am only able to read the data when the database is added to
the project and the connection string is as follows:

cn =
System.Configuration.ConfigurationManager.ConnectionStrings["WindowsFormsApplication1.Properties.Settings.Database1ConnectionString"].ConnectionString;


Why am I able to read the data using both connections but only able to
write when I use the physical path to the file?

It seems that as soon as I add the database to the project I am unable
to write to it.

Any thoughts?

You probably don't have write access to the file in the installation path,
such as c:\program files\my app\App_Data\nwind.mdb. Most systems lock
down c:\program files and below. You likely do have write access to a
file in the other location.
 
H

Harlan Messinger

John said:
Hello. I am experiencing a rather odd issue. I am able to both read
and write data to an Access database when my connection string is as
follows:

cn = "@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\nwind.mdb;Persist Security Info=True"

However, I am only able to read the data when the database is added to
the project and the connection string is as follows:

cn =
System.Configuration.ConfigurationManager.ConnectionStrings["WindowsFormsApplication1.Properties.Settings.Database1ConnectionString"].ConnectionString;


Why am I able to read the data using both connections but only able to
write when I use the physical path to the file?

It seems that as soon as I add the database to the project I am unable
to write to it.

Any thoughts?

Check your directory access. You have to have write access to the
directory containing the MDB file because when you open it, if Access
can't create an LDB locking file in the same directory, it will open the
database in read-only mode.
 
A

Andy O'Neill

Well you could google on
Howto: include a data file in a clickonce application
Read the msdn entry you find and then those linked to at the end.

John W said:
Thanks. Was considering that. I'm using ClickOnce technology to deploy
the application and corresponding files. I figure I have to add the
Access db to the project in order for it to get included with the
ClickOnce package. Only problem then is that I cant write to it. I need
somehow to include the Access db in the package and have it written to a
different directory. Just cant figure out how to do that.

Family Tree Mike said:
Forgot to mention. The app.config contains the following info for the
connection string:

<add
name="WindowsFormsApplication1.Properties.Settings.nwindConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\nwind.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />

Very strange that I can read the data no problem using eith of the
connections but cannot write when using the connection from app.config
(database added to project).

Hello. I am experiencing a rather odd issue. I am able to both read
and write data to an Access database when my connection string is as
follows:

cn = "@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\nwind.mdb;Persist Security Info=True"

However, I am only able to read the data when the database is added to
the project and the connection string is as follows:

cn =
System.Configuration.ConfigurationManager.ConnectionStrings["WindowsFormsApplication1.Properties.Settings.Database1ConnectionString"].ConnectionString;


Why am I able to read the data using both connections but only able to
write when I use the physical path to the file?

It seems that as soon as I add the database to the project I am unable
to write to it.

Any thoughts?

You probably don't have write access to the file in the installation
path, such as c:\program files\my app\App_Data\nwind.mdb. Most systems
lock down c:\program files and below. You likely do have write access to
a file in the other location.
 
J

John W

Thanks for the replies everyone. So what's involved in ensuring that the
user will have write access to the |DataDirectory| ? I've tried setting the
app to full trust and stil experience the same problem.
 
J

John W

Thanks Andy. Found the article. I'm not signing the application in any
way. Is this an issue?

Andy O'Neill said:
Well you could google on
Howto: include a data file in a clickonce application
Read the msdn entry you find and then those linked to at the end.

John W said:
Thanks. Was considering that. I'm using ClickOnce technology to deploy
the application and corresponding files. I figure I have to add the
Access db to the project in order for it to get included with the
ClickOnce package. Only problem then is that I cant write to it. I need
somehow to include the Access db in the package and have it written to a
different directory. Just cant figure out how to do that.

Family Tree Mike said:
On 2/19/2010 7:04 PM, John W wrote:
Forgot to mention. The app.config contains the following info for the
connection string:

<add
name="WindowsFormsApplication1.Properties.Settings.nwindConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\nwind.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />

Very strange that I can read the data no problem using eith of the
connections but cannot write when using the connection from app.config
(database added to project).

Hello. I am experiencing a rather odd issue. I am able to both read
and write data to an Access database when my connection string is as
follows:

cn = "@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\nwind.mdb;Persist Security Info=True"

However, I am only able to read the data when the database is added to
the project and the connection string is as follows:

cn =
System.Configuration.ConfigurationManager.ConnectionStrings["WindowsFormsApplication1.Properties.Settings.Database1ConnectionString"].ConnectionString;


Why am I able to read the data using both connections but only able to
write when I use the physical path to the file?

It seems that as soon as I add the database to the project I am unable
to write to it.

Any thoughts?





You probably don't have write access to the file in the installation
path, such as c:\program files\my app\App_Data\nwind.mdb. Most systems
lock down c:\program files and below. You likely do have write access
to a file in the other location.
 
A

Andy O'Neill

John W said:
Thanks Andy. Found the article. I'm not signing the application in any
way. Is this an issue?

I think with vista you can have security issues and signing the app is one
of the steps to avoiding these.
If you're deploying to xp then I think it's less of an issue.
I've never used a local database with clickonce though.

Google is your friend.
 

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