Wiring up an App.Config file - deploying the App.Config file

D

dbuchanan

Hello,

(Is this the proper newsgroup?)

=== Background ===
I am building a solution with two projects.

One project is my data access layer which contains my DataSet as an xsd
file. The XSD file was built by draging tables from the Data Sources pane.
Auto-generated code created the files associated wtih the XSD file (xss,
xsc, cs).

The other project has a reference to the data access layer project and
contains my windows forms.

=== My Goal === (My two questions further down address parts of this goal.)
I want to add an app config file to the solution and have it contain the
connectionstring. I want to be able to edit this App.Config file after
deployment so that I can connect to the desired target database.

=== Question #1 ===
This question is about adding an App.Config file after the XSD file is
already configured:

When I create an XSD file after I add an App.Config file the
connectionString is automatically added to the config file and the XSD is
automatically wired up to the App.Config file.

However, when the XSD file is created first teh XSD and the App.Config file
are independant form one another - no automatic wiring occurs. How can I get
the App.Config file wired up to the XSD file? - I cannot edit any of the
files associated with the XSD file because the code is auto-generated.

#1) How do I add a App.Config file to a data access layer project with an
existing XSD file and have them appropriately wired up to each other?

=== Question #2 ===
This question is about deployment of the application when there is an
App.Config file in the data access layer:

The following test solution scenario illustrates my problem:

I created a test solution where I added a data access layer project (DAL)
and added the App.Config file before building the XSD file. I built the XSD
file by adding a table to the design surface. (the app.config and the xsd
are automatically wired up properly.) Then I added a windows form project
(WinFrmPrj) and add a reference to the DAL and added a form with a
dataGridView and wired it up to display a table of data. I built a Release
version of the project.

Looking at the respective bin\release folder structures I see the following:

DAL\bin\Release
- DAL.dll
- DAL.dll.config
- DAL.pdb

WinFrmPrj\bin\release
- DAL.dll
- DAL.pdb
- WinFrmPrj.exe
- WinFrmPrj.pdb
- WinFrmPrj.vshost.exe

The contents of the second folder "WinFrmPrj\bin\release" is what gets
deployed (as I understand), therefore the config file is not available! So
when I deploy to the target machine I have no config file to edit to target
the application to the desired database.

#2) How do I have the 'DAL.dll.config' or any editable config file available
after deployment so that it can be edited

Thank you for your help.

dbuchanan
 
C

Cowboy \(Gregory A. Beamer\)

Let's see if I can cover your issues:

First, you can have the .config file deploy with the app by right clicking
and choosing to have it added to the compilation. This is fine for changing
connection strings. But, the config is always at application level and not
library level. This means you have to change the app config for the
application (windows forms by your example) by adding the connection string
there. Even if you created at library level, you need to move the string up.
It gets much easier in Orcas.

Second, the TableAdapters are where you are really worried about, not the
XSD. The fact that the XSD is set to a particular database is a minor
inconvenience in most cases. To rewire, either recreate the XSD (worst case)
or right click the XSD and choose the menu item that reconfigures the XSD
(forget the name of the option). The other option is to create any XSD
pointed to the correct database and find the point where it pulls the
connection string in the actual code created underneath the XSD. You can
then alter that code. In VS 2005, however, this is a bit of a pain. I have
not delved into this, so I am not sure where you have to look.





--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
 
D

dbuchanan

Hello Gregory,

#1 - Question:
First, you can have the .config file deploy with the app by right clicking
and choosing to have it added to the compilation.

Where is this that option? When I right click the file in solution explorer
I see these:
Open
Open With...
Exclude From Project
Cut
Copy
Delete
Rename
Properties

When I right-click the design surface of the App.Config I see:
View Data Grid
Insert Snippet...
Surround With...
Go To Definition
Breakpoint >
Go To Disassembly
Cut
Copy
Paste
Outlining >
Properties

So how do I deploy the App.Config file into the applicaton release folder?

#2 - Question:
the config is always at application level and not library level...
Even if you created at library level...

What do you mean by "application level" and "library level"?

#3 - Question:
the TableAdapters are where you are really worried about, not the XSD

Why? the TableAdapters refer directly to the XSD and if the XSD is right
will not the TableAdapter function properly?

#4 - Question:
To rewire, either ... or right click the XSD and choose the menu item that
reconfigures the XSD (forget the name of the option).

Where do I right-click the XSD? When I right click the XSD file in solution
explorer I see this:
Open
Open With...
Exclude From Project
Cut
Copy
Delete
Rename
Properties

When I right-click the design surface I see:
Add
Paste
Select All
Show Relation Labels
Preview Data...
View Code
Properties

I believe I have been able to solve the wiring this way;

I added the App.Config file to the data access layer project. Then, by
editing the Value (ConnectionString) in the Settings.Settings under the
Project Properties it automatically added the connectionString value to the
..config file (along with adding the connectionString to the
Settings.Designer.cs file too). After doing a release building the config
file appeared in the dataAccessLayer\bin\Release folder. - But the .config
file did NOT appear in the Application\bin\Release folder. That is still the
big problem!

#5 - Question:
One last question. I have an MSDN Pro subscription and I have decision
authority for how this applicaiton is constructed. Would you suggest that I
complete this project using Visual Studio 2007 (Orcas)? Is there an easy
learning curve? (By the way I am working on Vista x64 if that has any
influence.)

Summary:
The wiring is solved.
The deployment is NOT solved.
Please reply to questions above.

Thank you,

dbuchanan
 
W

Walter Wang [MSFT]

Hi dbuchanan,

..NET can only load a default configuration file per AppDomain (which is by
default the .exe.config with the executing assembly), if the .exe uses
another .dll assembly, the .dll assembly cannot have its own configuration
file.

In your case, the DAL project has it's own app.config at design time, but
when it's used by the application, it's reading from the main application's
configuration file. Therefore you will have to merge the connection string
key from the DAL project into the main application project's configuration
file.

Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
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.
 
D

dbuchanan

Hi Walter,
you will have to merge the connection string key from the DAL project
into the main application project's configuration file.

How do I do this merge?

I have added a configuration file to the application project and used the
Properties Settings.Settings to add a connectionString for the Application
and put in the text of the strng for the value. As a result the
configuration file is populated with the connectionString. But! that is not
available to the DAL! How do I wire it up to do this?

Thank you,
dbuchanan
 
C

Cowboy \(Gregory A. Beamer\)

dbuchanan said:
Hello Gregory,

#1 - Question:

Where is this that option? When I right click the file in solution
explorer I see these:
Open
Open With...
Exclude From Project
Cut
Copy
Delete
Rename
Properties

When I right-click the design surface of the App.Config I see:
View Data Grid
Insert Snippet...
Surround With...
Go To Definition
Breakpoint >
Go To Disassembly
Cut
Copy
Paste
Outlining >
Properties

So how do I deploy the App.Config file into the applicaton release folder?

Sorry, it is in the Properties window. Copy to Output Directory. Only works
the config is always at application level and not library level...
Even if you created at library level...

What do you mean by "application level" and "library level"?[/QUOTE]

Whatever piece is actually running (web, windows, console, windows service)
has the config. it sounds like your DAL is compiled as a separate project
and is referenced by your application.
#3 - Question:

Why? the TableAdapters refer directly to the XSD and if the XSD is right
will not the TableAdapter function properly?

You can port an XSD anywhere, as it is merely a schema definition. When you
add TableAdapters, you start having code
#4 - Question:

Where do I right-click the XSD? When I right click the XSD file in
solution explorer I see this:
Open
Open With...
Exclude From Project
Cut
Copy
Delete
Rename
Properties

When I right-click the design surface I see:
Add
Paste
Select All
Show Relation Labels
Preview Data...
View Code
Properties

On the XSD file, you should see Run Custom Tool. I was probably thinking
about WSDL (service references) when I wrote this originally, but the Run
Custom Tool should fix broken XSDs. I have not tried with TableAdapters sans
web.config entries in the past, however.
I believe I have been able to solve the wiring this way;

I added the App.Config file to the data access layer project. Then, by
editing the Value (ConnectionString) in the Settings.Settings under the
Project Properties it automatically added the connectionString value to
the .config file (along with adding the connectionString to the
Settings.Designer.cs file too). After doing a release building the config
file appeared in the dataAccessLayer\bin\Release folder. - But the .config
file did NOT appear in the Application\bin\Release folder. That is still
the big problem!

Config is always at the application level, not in the library projects
referenced by the application.
#5 - Question:
One last question. I have an MSDN Pro subscription and I have decision
authority for how this applicaiton is constructed. Would you suggest that
I complete this project using Visual Studio 2007 (Orcas)? Is there an easy
learning curve? (By the way I am working on Vista x64 if that has any
influence.)

Orcas gives you more options. If you can wait to release until later this
year (Go Live license) or next year (RTM) I would consider heading this
direction. If fall, you have to gauge how squeamish the execs will be with
Go Live versus a release product. (Go Live means there will be support for
RTM "upgrade").

In Orcas, you have the option of separating your data sets into DAL and
business object components. This allows you to keep the tricky parts, like
TableAdapters, from the definition. Much cleaner. There are some neat
webcasts on this already.

In addition, you can use LINQ to query the database in a neutral way. Simply
switching out LINQ libraries is the path to move from one type of server to
another. It is not quite that simple at present, but I think they can get
there.
Summary:
The wiring is solved.
The deployment is NOT solved.
Please reply to questions above.





--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
 
W

Walter Wang [MSFT]

Hi dbuchanan,

So far you will have to manually merge the connection string you used into
the main application configuration file. Currently we don't have automatic
processing for it, sorry for the inconvenience.


Regards,
Walter Wang ([email protected], remove 'online.')
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.
 
D

dbuchanan

Hi Cowboy
Whatever piece is actually running (web, windows, console, windows
service) has the config. it sounds like your DAL is compiled as a separate
project and is referenced by your application.

You are not specific enough! Which one did you describe in "Whatever piced
is actually running"?
Application level? or Library level?
 
D

dbuchanan

Hi Walter,
So far you will have to manually merge the connection string you used into
the main application configuration file. Currently we don't have automatic
processing for it, sorry for the inconvenience.

But how is this done?
 
N

Nick

To create a WinFrmPrj.config file with a <connectionStrings> element and a
connection string in a child <add> element used by the DAL tableadapters:

Bring up the WinFrmPrj project property page from the menu and select the
Settings tab. Enter the name of the connectionstring, select Type
(Connection string) and set the value to the connection string text.

Open DAL.dll.config to get a sense of what WinFrmPrj.config should contain.
Hope this helps.
 
W

Walter Wang [MSFT]

Hi dbuchanan,

As Nick pointed out, for Settings, you can use the Settings Designer to
manually copy the same entries from your DAL project to the main
application project. For other settings, you will have open the .config
file in editor and copy relevant elements manually.



Regards,
Walter Wang ([email protected], remove 'online.')
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.
 
H

harveyliu168

Hello,

(Is this the proper newsgroup?)

=== Background ===
I am building a solution with two projects.

One project is my data access layer which contains my DataSet as an xsd
file. The XSD file was built by draging tables from the Data Sources pane.
Auto-generated code created the files associated wtih the XSD file (xss,
xsc, cs).

The other project has a reference to the data access layer project and
contains my windows forms.

=== My Goal === (My two questions further down address parts of this goal.)
I want to add anapp configfile to the solution and have it contain the
connectionstring. I want to be able to edit thisApp.Configfile after
deployment so that I can connect to the desired target database.

=== Question #1 ===
This question is about adding anApp.Configfile after the XSD file is
already configured:

When I create an XSD file after I add anApp.Configfile the
connectionString is automatically added to the config file and the XSD is
automatically wired up to theApp.Configfile.

However, when the XSD file is created first teh XSD and theApp.Configfile
are independant form one another - no automatic wiring occurs. How can I get
theApp.Configfile wired up to the XSD file? - I cannot edit any of the
files associated with the XSD file because the code is auto-generated.

#1) How do I add aApp.Configfile to a data access layer project with an
existing XSD file and have them appropriately wired up to each other?

=== Question #2 ===
This question is about deployment of the application when there is anApp.Configfile in the data access layer:

The following test solution scenario illustrates my problem:

I created a test solution where I added a data access layer project (DAL)
and added theApp.Configfile before building the XSD file. I built the XSD
file by adding a table to the design surface. (theapp.configand the xsd
are automatically wired up properly.) Then I added a windows form project
(WinFrmPrj) and add a reference to the DAL and added a form with a
dataGridView and wired it up to display a table of data. I built a Release
version of the project.

Looking at the respective bin\release folder structures I see the following:

DAL\bin\Release
- DAL.dll
- DAL.dll.config
- DAL.pdb

WinFrmPrj\bin\release
- DAL.dll
- DAL.pdb
- WinFrmPrj.exe
- WinFrmPrj.pdb
- WinFrmPrj.vshost.exe

The contents of the second folder "WinFrmPrj\bin\release" is what gets
deployed (as I understand), therefore the config file is not available! So
when I deploy to the target machine I have no config file to edit to target
the application to the desired database.

#2) How do I have the 'DAL.dll.config' or any editable config file available
after deployment so that it can be edited

Thank you for your help.

dbuchanan

As the Setting.Settings class ia a partial class, you can customise it
by providing your partial class and forget about the app.config file.
 
N

nateastle

Hello,

(Is this the proper newsgroup?)

=== Background ===
I am building a solution with two projects.

One project is my data access layer which contains my DataSet as an xsd
file. The XSD file was built by draging tables from the Data Sources pane.
Auto-generated code created the files associated wtih the XSD file (xss,
xsc, cs).

The other project has a reference to the data access layer project and
contains my windows forms.

=== My Goal === (My two questions further down address parts of this goal.)
I want to add an app config file to the solution and have it contain the
connectionstring. I want to be able to edit this App.Config file after
deployment so that I can connect to the desired target database.

=== Question #1 ===
This question is about adding an App.Config file after the XSD file is
already configured:

When I create an XSD file after I add an App.Config file the
connectionString is automatically added to the config file and the XSD is
automatically wired up to the App.Config file.

However, when the XSD file is created first teh XSD and the App.Config file
are independant form one another - no automatic wiring occurs. How can I get
the App.Config file wired up to the XSD file? - I cannot edit any of the
files associated with the XSD file because the code is auto-generated.

#1) How do I add a App.Config file to a data access layer project with an
existing XSD file and have them appropriately wired up to each other?

=== Question #2 ===
This question is about deployment of the application when there is an
App.Config file in the data access layer:

The following test solution scenario illustrates my problem:

I created a test solution where I added a data access layer project (DAL)
and added the App.Config file before building the XSD file. I built the XSD
file by adding a table to the design surface. (the app.config and the xsd
are automatically wired up properly.) Then I added a windows form project
(WinFrmPrj) and add a reference to the DAL and added a form with a
dataGridView and wired it up to display a table of data. I built a Release
version of the project.

Looking at the respective bin\release folder structures I see the following:

DAL\bin\Release
- DAL.dll
- DAL.dll.config
- DAL.pdb

WinFrmPrj\bin\release
- DAL.dll
- DAL.pdb
- WinFrmPrj.exe
- WinFrmPrj.pdb
- WinFrmPrj.vshost.exe

The contents of the second folder "WinFrmPrj\bin\release" is what gets
deployed (as I understand), therefore the config file is not available! So
when I deploy to the target machine I have no config file to edit to target
the application to the desired database.

#2) How do I have the 'DAL.dll.config' or any editable config file available
after deployment so that it can be edited

Thank you for your help.

dbuchanan

I ran into this issue a while back. There are many different solutions
to getting your .dll to read a config file so you can deploy it
independently of your application. I found the second easiest thing to
do was to write my own parser to read the application settings and
connection strings for the config file. The easiest thing to do, that
was disused is to include your settings at the application level
(where the .exe project is at). There is an article out there about
creating a separate app that your dll is running in that can read it's
settings but it's more complicated than it is worth.
 

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