Gustav Brock
gustav at cactus.dk
Fri Jan 14 15:29:02 CST 2011
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