1

My program used to start even though Mysql is offline, it will open but give an indicator that the program is not connected to the database, which is what i want. I want it to start even if the database is offline and just give an indicator that its not connected I set a connection indicator like this:

public void connStatus()
        {
            MySqlConnection myConn = new MySqlConnection("SERVER = localhost; user id = root; password =; database = mpdb");
            try
            {
                myConn.Open();
                dbconsign.Visible = true;
                dbnotconsign.Visible = false;
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(this, ex.Message , "NOTIFICATION", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                dbconsign.Visible = false;
                dbnotconsign.Visible = true;
            }
            finally
            {
                if (myConn.State == ConnectionState.Open)
                {
                    myConn.Close();
                }
            }
        }

(I know that my code above is not the best one for checking server connections, but i just needed something to indicate if the database is online or offline, im new to programming and im not very good at it yet.)

now, after I added some dll's and went on with my little program, the program will only start if Mysql is Online. It won't start at all and will give messages like this:

    Could not find schema information for the element 'setting'.
    Could not find schema information for the element 'value'.  

so i figured out something is wrong at the App.Config, and the problem is I only have little knowledge on XML and i don't understand whats going on with the one on my project. Can someone please tell me why is this happening? and how do i fix it? Any suggestions and corrections are highly appreciated.

this is the App.config of my project:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="cpsfmV2._0.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
    <userSettings>
        <cpsfmV2._0.Properties.Settings>
            <setting name="CurrentDate" serializeAs="String">
                <value />
            </setting>
        </cpsfmV2._0.Properties.Settings>
    </userSettings>
<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.9.12.0" newVersion="6.9.12.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
  • you can't start your program? occur some error? what's error message? – LimGeomJe Mar 08 '19 at 12:50
  • this is what it says "An unhandled exception of type 'System.NullReferenceException' occurred in MetroFramework.dll". – princessbubbles15 Mar 08 '19 at 13:00
  • 1
    Can you try deleting the section of app.config starting at `` and ending at the close tag ``? – Thomas N Mar 08 '19 at 13:03
  • when i did remove the section you told me to delete, all 6 messages saying that "Could not find schema information for the element '' ", but still, the program wont start and keeps on saying,An unhandled exception of type 'System.NullReferenceException' occurred in MetroFramework.dll Additional information: Object reference not set to an instance of an object. im confused,i was using the MetroFramework even before this problem happened and nothing was wrong with it. :( – princessbubbles15 Mar 08 '19 at 13:12
  • Where does the error occur? source code line. – LimGeomJe Mar 08 '19 at 13:32
  • it says something is wrong here `MetroMessageBox.Show(this, ex.Message, "NOTIFICATION", MessageBoxButtons.OK, MessageBoxIcon.Hand);` – princessbubbles15 Mar 08 '19 at 13:35

1 Answers1

0

I am so happy i learned something new today,i just learned about proper debugging today thanks to google and stackoverflow. I tried to google stuff related to NullReference Exception i found a very helpful guide from this post, not exactly the answer but the guy on the post explained it in easily understandable terms for newbies like me. What is a NullReferenceException, and how do I fix it?

though the error says:

'System.NullReferenceException' occurred in MetroFramework.dll Additional information: Object reference not set to an instance of an object.

which got me confused as a beginner, i read on the post linked above that you need to check for the InnerException, which i did and led me to my other mistake which says

System.TypeInitializationException

and it turns out its all because of a variable i declared from another class.

someone whos a newbie like me might get the same problem so i'll share the posts that helped me. how to solve System.TypeInitializationException was unhandled exception in vb.net? Field xxx is never assigned to, and will always have its default value null

and the final solution to my problem was i turned this:

private AuditTrail audittrail = new AuditTrail();
private void loginbtn_Click(object sender, EventArgs e)
{
            //some code here
            audittrail.RecordLogin();
}

into this:

private AuditTrail audittrail;
private void loginbtn_Click(object sender, EventArgs e)
{
            audittrail = new AuditTrail();
            //some code here
            audittrail.RecordLogin();
}

and now its working :) Thanks to the helpful posts above.