How can I see the way access to the connection string is made

T

Tony Johansson

Hello!

I just wonder how can I see the way the program access the xml file
app.config/DisplayProducts.exe.config
I do know how to establich a connection to the database by writing code but
I just want to find out
how code the is generated is doing this.

I have done the following.
1.Create a window project with name WindowsApplication1
2.Select Add New Data Source.. on the Data tool bar in VS so dialog Data
Source Configuration Wizard is being shown
3.Select Database from Data Source Configuration Wizard and click Next
4.Choose a valid DataConnection from dialog Data Source Configuration Wizard
I select hempc\sqlexpress.Northwind.dbo and Click Next
5. Indicate that you want to save the connection string
I gave the name NorthwindConnectionString and click Next
6. I selected two tables from the Nortwind database. These are Products and
Suppliers
7.Click Finish

When you have clicked Finish 5 new files has been created in the project.
These are
app.config and
-NorthwindDataSet.xsd
NorthwindDataSet.Designer.cs
NorthwindDataSet.xsc
NorthwindDataSet.xss

In folder Bin/Debug we have an xml file called
WindowsApplication1.exe.config which is a copy of app.config

Now we click on Show Data Source on the data tool bar.
In the DataSource that is displayed we can see the DataSet NorthwindDataSet
and
the two DataTables Products and Suppliers.
Here we have a one to many relation one Supplier can delier many products
but one product can only be
delivered by one supplier.

Click on the DataTable Suppliers and choose from combo Details.
Drag the DataTable Supplier into the Form.
Drag the DataTable Product that is encapsulated in Supplier into the form
and place it to the right of the other one.

Now to my question that I mentioned in the beginning when I run the program
a connection to the database is made
and I just want to find out the way the program is using
app.config/WindowsApplication1.exe.config because the
connectionstring is located in these xml files.

//Tony
 
A

Alberto Poblacion

Tony Johansson said:
Now to my question that I mentioned in the beginning when I run the
program
a connection to the database is made
and I just want to find out the way the program is using
app.config/WindowsApplication1.exe.config because the
connectionstring is located in these xml files.

If you open the file NorthwindDataSet.Designer.cs, you will find a line like
this:

this._connection.ConnectionString =
global::WindowsFormsApplication1.Properties.Settings.Default.NorthwindConnectionString;

There you see how the designer-generated code is using the
Properties.Settings (which are saved in the xml file) to retrieve the
connection string.
 

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