OleDbConnectionStringBuilder and .Net 2.0 Datasets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a set of datasets that I build in 2.0 that reference a
Settings/Connection string called,
name="PDS.LSS.Properties.Settings.StateConnectionString".

I have a method that allows my users to either create a new MDB or select a
existing MDB to reference these database objects.

My problem is that the OleDbConnectionStringBuilder appears to not allow me
to change/set this connection string name.

I define a string DBPath = string that contains the absolute path to the
either created or existing MDB file and I need to inject it into the
ConnectionString names above, but I cannot find the right syntax or flow to
allow this to happen.

Any Suggestions??? Thanks All!

David
 
Hi David,

Do you mean that you need to concatenate the path and file name strings? If
so, just use

string FullName = DBPath + Filename;

If you need to inject the DBPath to an existing connection string, try to
create an OleDbConnectionStringBuilder object from the connection string
and set the DataSource property of it.

OleDbConnectionStringBuilder csb = new
OleDbConnectionStringBuilder(connstr);
csb.DataSource = DBPath + Filename;

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Ok, my existing connection string looks like this;

<connectionStrings>
<add name="PDS.LSS.Properties.Settings.LookupDataConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\DataStore\LookupData.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
</connectionStrings>

I need to be able to change the datasource of this string, but the api won't
let me edit this string. All of my Datasets connecto to this datasource.

Does that make sense?

Thanks;
David
 
Hi David,

Do you want to add the DataDirectory as directory name before current
datasource? If so, here is an example I wrote.

OleDbConnectionStringBuilder sb = new
OleDbConnectionStringBuilder(@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=DataStore\LookupData.mdb;Persist Security Info=True");
string dir = @"c:\DataDirectory\";
sb.DataSource = dir + sb.DataSource;
OleDbConnection cnn = new OleDbConnection(sb.ConnectionString);

HTH.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
No, what I am trying to do is change the current path to a connection string
created via the default data providers.

The DotNet 2.0 Dataset objects in VS2005 create a connection string like this;

<add name="PDS.LSS.Properties.Settings.StateConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\DataStore\LS_Shell.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />

What I need to do is change this connection string in running memory; so
that I can change the actual running file on the fly, versus have to change
the app.config file each time I want to connect to a different database using
the stored datasets.

Does that make sense?
 
Hi David,

Do you mean that you need to write the changed connection string back to
app.config file? We cannot do that because app.config file is a read-only
file, if you really need to modify the file programatically, you have to
parse it as an xml file using DOM and do the modification. HTH.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
no, but I have this connection string in my app.config that is bound to all
of these controls. What is the best way to repath this particular
connectionstring?
 
Hi David,

You can use a certain class, for example, named Settings and use a static
property to provide the connection string for all the controls. When app
starts, Settings.ConnectionString will get the connection string from
app.config file, and save it in an internal variable. If you need to change
it on the fly, just change that variable and the Settings.ConnectionString
property will return the new connection string instead.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top