This is a migrated thread and some comments may be shown as answers.

How to create Application file in xaml????

5 Answers 248 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
kottu
Top achievements
Rank 1
kottu asked on 03 Sep 2009, 11:46 AM

I need Connection strings examples in xaml??????????

anyone can help me !!!!!

Regards,
vignesh

5 Answers, 1 is accepted

Sort by
0
Roland
Top achievements
Rank 1
answered on 09 Sep 2009, 03:06 PM
Create normal App.config file and there is a <connectionStrings/> section in it you could use.

Then in code you use ConfigurationManager class to get the connection string you want.

0
kottu
Top achievements
Rank 1
answered on 10 Sep 2009, 06:16 AM
thanks for ur reply ...

<Application x:Class="wpfsampleapp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wpfsampleapp="clr-namespace:wpfsampleapp"
    StartupUri="Window1.xaml">
    
    <Application.Resources>
       
   </Application.Resources>
</Application>

were to use connection string ......
send me some examples ......
regards,
vignesh


0
Roland
Top achievements
Rank 1
answered on 10 Sep 2009, 02:03 PM
Add new item -> Application Configuration file   (this is app.config)

Put:
<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
  <connectionStrings> 
    <add name="myConnection" connectionString="Server=(local);Database=Test;Integrated Security=True"/> 
     
  </connectionStrings> 
</configuration> 

In there.

Create Window1.xaml:
<Window x:Class="WpfApplication4.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="300" Width="300"
    <Grid> 
        <TextBlock x:Name="txtConn" /> 
    </Grid> 
</Window> 
 

in Window1.xaml.cs:

using System.Configuration; 
using System.Windows; 
namespace WpfApplication4 
    /// <summary> 
    /// Interaction logic for Window1.xaml 
    /// </summary> 
    public partial class Window1 : Window 
    { 
        public Window1() 
        { 
            InitializeComponent(); 
            txtConn.Text = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString; 
        } 
    } 
 
Done.

This is the way to go. You dont want to embed your connection string in XAML, because you wont be able to change it during runtime if DB has changed etc.
0
kottu
Top achievements
Rank 1
answered on 11 Sep 2009, 05:47 AM

Thanks 4 ur reply,

 

im check ur coding

 Configuration manager is not working .......

 

help me sir.......

 

 

regards,

vignesh

0
Roland
Top achievements
Rank 1
answered on 11 Sep 2009, 01:18 PM
Add reference to System.Configuration assembly.
Tags
General Discussions
Asked by
kottu
Top achievements
Rank 1
Answers by
Roland
Top achievements
Rank 1
kottu
Top achievements
Rank 1
Share this question
or