Connection property has not been initialized.

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Zer0

Connection property has not been initialized.

Post by Zer0 » Mon 24 Jul 2006 08:31

When I run the text below I get this error ..

Code: Select all

if (box2.Text == box3.Text & mySqlConnection1.State == ConnectionState.Open)
            {
                try
                {
                    mySqlScript1.Execute();
                }
                catch (System.Exception)
                {
                    textBox4.AppendText("Username Taken,\r\nPlease try a different one.");
                    //mySqlConnection1.Close();
                }
                this.mySqlScript2.Name = "mySqlScript2";
                this.mySqlScript2.ScriptText = "INSERT INTO 'accounts' VALUES ('username.Text', 'box2.Text', '1');";
                mySqlScript2.Execute();
                textBox4.AppendText(" You are now registered ");

            }
ANy help with this is greatly appreciated

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Mon 24 Jul 2006 08:47

Connection property of mySqlScript1 component has not been initialized in your code. Do this first before running mySqlScript1.Execute()

Zer0

Post by Zer0 » Mon 24 Jul 2006 08:58

Then I get issues with the ; not being there
Error 1 ; expected C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Rose Launcher\Rose Launcher\Form2.cs 79 43 Rose Launcher

Code: Select all

 if (box2.Text == box3.Text & mySqlConnection1.State == ConnectionState.Open)
            {
                try
                {
                    //mySqlScript1.Connection = mySqlScript1.Connection;
                    mySqlScript1.Execute()
                    mySqlScript1.Execute();
                }
                catch (System.Exception)
                {
                    textBox4.AppendText("Username Taken,\r\nPlease try a different one.");
                    //mySqlConnection1.Close();
                }
                this.mySqlScript2.Name = "mySqlScript2";
                this.mySqlScript2.ScriptText = "INSERT INTO 'accounts' VALUES ('username.Text', 'box2.Text', '1');";
                //mySqlScript2.Connection = mySqlScript2.Connection;
                mySqlScript2.Execute()
                mySqlScript2.Execute();
                textBox4.AppendText(" You are now registered ");
I added in the mySqlScript2.Execute() and mySqlScript1.Execute()

Zero

Post by Zero » Mon 24 Jul 2006 09:01

n/m .. how to I set the connection ?

Code: Select all

mySqlScript2.Connection = mySqlScript2.Connection;
?

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Mon 24 Jul 2006 10:53

Use the following code:

Code: Select all

      mySqlConnection1.ConnectionString = "User Id=root;Password=root;Host=localhost;Database=test;";
      mySqlScript1.Connection = mySqlConnection1;
      mySqlConnection1.Open();
      mySqlScript1.Execute();

Post Reply