Shamil Salakhetdinov
shamil at smsconsulting.spb.ru
Fri Jan 14 16:09:27 CST 2011
Thank you, Gustav,
First of all I do use MS Access backend for that my simple application.
Yes, I can write a couple of code lines to customize connection creation on
runtime but I wanted to avoid doing that additional coding.
The following static solution works well
<connectionStrings>
<add
name="ProductPicturesLocator.Properties.Settings.TestDataConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=.\Database\TestData.mdb"
providerName="System.Data.OleDb" /> </connectionStrings>
I just need to keep watching to have current directory within that
application to be always equal to the app.config's assembly directory...
Thank you.
--
Shamil
-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: 15 ?????? 2011 ?. 0:29
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] How to specify a relative path to an MS Access db
inapp.config?
Hi Shamil
This guy seems to have found a method to specify a relative path as a
parameter - which is little different from your connection string:
http://www.eggheadcafe.com/community/aspnet/2/10213449/set-relative-path-in-
windows-application.aspx
However, you later should be able to easily modify your connection string
using the SqlConnectionStringBuilder:
private SqlConnection ConnectionApplyPassword(string
connectionString)
{
// Apply password to connectionString.
SqlConnectionStringBuilder sqlConnectionStringBuilder = new
SqlConnectionStringBuilder();
sqlConnectionStringBuilder.ConnectionString = connectionString;
sqlConnectionStringBuilder.Password = _connectionDbPassword;
return new SqlConnection(sqlConnectionStringBuilder.ToString());
}
like this:
someDataTableAdapter.Connection =
ConnectionApplyPassword(someDataTableAdapter.Connection.ConnectionString);
/gustav
>>> shamil at smsconsulting.spb.ru 14-01-2011 17:51 >>>
Hi All --
That should be simple(?) but google somehow doesn't give any useful feedback
(or I'm missing it).
I wanted to have the following connection string from app.config to use
relative path to MS Access db - relative to the folder where app.config (its
assembly) will be installed on target system:
<connectionStrings>
<add
name="ProductPicturesLocator.Properties.Settings.TestDataConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=.\Database\TestData.mdb"
providerName="System.Data.OleDb" /> </connectionStrings>
If I write:
Data Source=.\Database\TestData.mdb
it works on start-up and when I work with main form, but as soon as I use,
e.g., OpenFile fialog, which changes default folder main form's update which
is bound do a dataset which uses the above connection string fails to update
db as it gets now improper fullpath for db...
Isn't there something like
Data Source=~\Database\TestData.mdb
or
Data Source={Application}\Database\TestData.mdb
or
...
way to specify "stable" relative path to the MS Access db - relative to the
app.config's assembly location?
I do not want to use DSN...
Thank you.
--
Shamil
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com