Hi all,
I have a database "Books-Authors" (with 2 tables) in my Microsoft SQL Server 2012 Management Studio. In the WPF application of Microsoft Visual Studio 2012 Express, I launched a project of databiding and connection string (named"scWpfApp1_BookAuthors") for displaying the desired/extracted data of the database "Books-Authors" on the FillDataGrid of my WPF application "scWpfApp1_BookAuthors". MainWindow.xaml.cs is:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Configuration; using System.Data; using System.Data.SqlClient; namespace scWpfApp1_BookAuthors { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); FillDataGrid(); } private void FillDataGrid() { String ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; String CmdString = String.Empty; using (SqlConnection con = new SqlConnection(ConString)) { CmdString = "Select BookID, BookTitle, AuthorID from dbo.Table_1_Books"; SqlCommand cmd = new SqlCommand(CmdString, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable("Books"); sda.Fill(dt); DataGrid_Loaded.ItemsSource = dt.DefaultView; } } } }
I did BUILD on this project OK. But, I did START Without DEBUGGING and I got the message: scWpfApp1_BookAuthors has stopped working. I did Debugging and I got the following messages:
Image may be NSFW.
Clik here to view.
I don't know why the "ConString" does not work. Please kindly help, tell me where I made the mistales in Connection Strings and/or Data Binding, and how to resolve the problem. Thanks in advance, Scott Chang
P. S. App.config is:
<?xml version="1.0" encoding="utf-8" ?><configuration><configSections></configSections><connectionStrings><add name="ConString" connectionString="Data Source=NAB-WK-02657306\SQLEXPRESS;Initial Catalog=BooksAuthorsLibrary;Integrated Security=True" providerName="System.Data.SqlClient" /></connectionStrings><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup></configuration>