Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. The ConnectionString property has not been initialized !

The ConnectionString property has not been initialized !

Scheduled Pinned Locked Moved C#
helpdatabase
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mostafa_h
    wrote on last edited by
    #1

    Hi Everybody ! in btnShow_Click() : try { string query="Select * from TestReport"; con.Open(); da=new SqlDataAdapter(query,con); sqlcmb=new SqlCommandBuilder(da); da.Fill(DS,"TestReport"); dt = DS.Tables["TestReport"]; dv = dt.DefaultView; dataGrid1.DataSource=dv; con.Close(); sqlcmb.Dispose(); con.Dispose(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } at the first I have no problem for showing records , but at the second when I press th Show Button , I have this error : The ConnectionString property has not been initialized ! thanx for any help ! Regards ,

    s_mostafa_h

    N C 2 Replies Last reply
    0
    • M mostafa_h

      Hi Everybody ! in btnShow_Click() : try { string query="Select * from TestReport"; con.Open(); da=new SqlDataAdapter(query,con); sqlcmb=new SqlCommandBuilder(da); da.Fill(DS,"TestReport"); dt = DS.Tables["TestReport"]; dv = dt.DefaultView; dataGrid1.DataSource=dv; con.Close(); sqlcmb.Dispose(); con.Dispose(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } at the first I have no problem for showing records , but at the second when I press th Show Button , I have this error : The ConnectionString property has not been initialized ! thanx for any help ! Regards ,

      s_mostafa_h

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello Your problem is in this line:

      con.Dispose();

      You shouldn't dispose the connection if you'll use it again. also I don't recommend opening/closing the connection each time you make a query. Regards:rose:

      M 1 Reply Last reply
      0
      • N Nader Elshehabi

        Hello Your problem is in this line:

        con.Dispose();

        You shouldn't dispose the connection if you'll use it again. also I don't recommend opening/closing the connection each time you make a query. Regards:rose:

        M Offline
        M Offline
        mostafa_h
        wrote on last edited by
        #3

        hi there , but , if it does'nt Dispose() , eachtime , I press the button , all previous records is added again to the end of record . thanx a lot ,

        s_mostafa_h

        S N 2 Replies Last reply
        0
        • M mostafa_h

          hi there , but , if it does'nt Dispose() , eachtime , I press the button , all previous records is added again to the end of record . thanx a lot ,

          s_mostafa_h

          S Offline
          S Offline
          Steve
          wrote on last edited by
          #4

          Try clearing your data objects explicitly rather than disposing the connection.

          M 1 Reply Last reply
          0
          • M mostafa_h

            Hi Everybody ! in btnShow_Click() : try { string query="Select * from TestReport"; con.Open(); da=new SqlDataAdapter(query,con); sqlcmb=new SqlCommandBuilder(da); da.Fill(DS,"TestReport"); dt = DS.Tables["TestReport"]; dv = dt.DefaultView; dataGrid1.DataSource=dv; con.Close(); sqlcmb.Dispose(); con.Dispose(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } at the first I have no problem for showing records , but at the second when I press th Show Button , I have this error : The ConnectionString property has not been initialized ! thanx for any help ! Regards ,

            s_mostafa_h

            C Offline
            C Offline
            Coding C
            wrote on last edited by
            #5

            Hi, try setting the con.ConnectionString property before opening the connection ie, use con.ConnectionString="your connectionstring"; con.Open(); hope this works. Nitin...

            1 Reply Last reply
            0
            • S Steve

              Try clearing your data objects explicitly rather than disposing the connection.

              M Offline
              M Offline
              mostafa_h
              wrote on last edited by
              #6

              connection(con) has not any property for "Clear()" , Ccan u more explain , plz?;)

              s_mostafa_h

              1 Reply Last reply
              0
              • M mostafa_h

                hi there , but , if it does'nt Dispose() , eachtime , I press the button , all previous records is added again to the end of record . thanx a lot ,

                s_mostafa_h

                N Offline
                N Offline
                Nader Elshehabi
                wrote on last edited by
                #7

                Hello You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the DataGridView.Rows.Clear() method before filling it again. Regards:rose:

                S 1 Reply Last reply
                0
                • N Nader Elshehabi

                  Hello You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the DataGridView.Rows.Clear() method before filling it again. Regards:rose:

                  S Offline
                  S Offline
                  Steve
                  wrote on last edited by
                  #8

                  Nader Elshehabi wrote:

                  You shouldn't dispose your connection until you don't need it anymore in the current session. If you want to clear you DataGridView -as I understood from your reply-, then you should call the DataGridView.Rows.Clear() method before filling it again.

                  This is what I was getting at - sorry for the lack of detail.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups