Thread: The ConnectionString property has not been initialized.

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    1

    The ConnectionString property has not been initialized.

    I'm trying to write a registration form in windows application and insert the information to a SQL Database !

    I got this error ! :

    ************** Exception Text **************
    System.InvalidOperationException: The ConnectionString property has not been initialized.
    at System.Data.Common.DbDataAdapter.UpdatingRowStatus Errors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow)
    at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
    at System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable dataTable, DataTableMapping tableMapping)
    at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
    at FingerAppNet.Register.btnRegister_Click(Object sender, EventArgs e) in C:\******\Register.cs:line 114 ( This Line : da.Update(ds1, "Reg"); )

    Here's my code :

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;      // For the database connections and objects.
    using System.Data.Common;
    using System.Configuration;
    
    namespace FingerAppNet
    {
        public partial class Register : Form
        {
            public Register()
            {
                InitializeComponent();
            }
    
            System.Data.SqlClient.SqlConnection con;
    
            int MaxRows = 0;
            int inc = 0;
    
            private void Register_Load(object sender, EventArgs e)
            {
                con = new System.Data.SqlClient.SqlConnection();
    Source=|DataDirectory|\\Reg.mdf";
                ds1 = new DataSet();
                con.ConnectionString ="Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Reg.mdf;Integrated Security=True;User Instance=True";
                string sq1 = "SELECT * FROM RegisterUser";
                da = new System.Data.SqlClient.SqlDataAdapter(sq1, con);
                con.Open();
                da.Fill(ds1, "Reg");
    
                con.Close();
                con.Dispose();
            }
    
    private void btnRegister_Click(object sender, EventArgs e)
            {
    
                if (tbtPassword.Text != tbtConfirmPassword.Text)
                {
                    MessageBox.Show("passwords are not Match!");
    
                }
                else
                {
                    MessageBox.Show("The details are fine");
    
                    System.Data.SqlClient.SqlCommandBuilder cb;
                    cb = new System.Data.SqlClient.SqlCommandBuilder(da);
                    DataRow dRow = ds1.Tables["Reg"].NewRow();
    
                    dRow[1] = tbtUserName.Text;
                    dRow[2] = tbtPassword.Text;
                    dRow[3] = tbtConfirmPassword.Text;
                    dRow[4] = tbtImage.Text;
    
                    ds1.Tables["Reg"].Rows.Add(dRow);
    
                    MaxRows = MaxRows + 1;
                    inc = MaxRows - 1;
    
                    da.Update(ds1, "Reg");
    
                    MessageBox.Show("added");
    
                }
    
            }
    Can someone tell me how to fix it ?
    Last edited by shembelcut; 08-23-2009 at 01:17 AM.

  2. #2
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Code:
    con.ConnectionString =@"Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Reg.mdf;Integrated Security=True;User Instance=True";
    I haven't read your whole code but this might be the problem. The @ should prevent you needing to escape everything

    Also
    Code:
    Source=|DataDirectory|\\Reg.mdf";
    has a typo here. You're missing a ".
    Last edited by WDT; 08-23-2009 at 12:13 PM.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static property
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-12-2008, 01:03 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. C++/CLI Property
    By psychopath in forum Windows Programming
    Replies: 5
    Last Post: 07-11-2006, 09:45 PM
  4. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 09:54 AM
  5. Property Sheets :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 05-09-2002, 03:04 PM

Tags for this Thread