Share via


SQL Connection working on DEBUG mode not on RELEASE

Question

Sunday, November 20, 2016 10:25 AM

Hey guys,

I have a problem with connecting to database.

Everything works well on debug mode, but when I'm changing to RELEASE mode "Application Unfortunately has Stopped". There is a problem with "con.Open();

What is going on here.

MySqlConnection con = new MySqlConnection("Server=bartuszak.pl;Port=3306;database=android;User Id=android;charset=utf8");

            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();


                    MySqlCommand cmd = new MySqlCommand();
                    cmd.CommandText = string.Format("SELECT ID,User_FirstName FROM Users WHERE User_Email ='" + txtEmailZaloguj.Text + "' AND User_Password='" + txtPasswordZaloguj.Text + "'");
                    cmd.Connection = con;
                    MySqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        ZalogujSuccess = true;
                        int ID = int.Parse(reader.GetString(0));
                        string User_FirstName = reader.GetString(1);

                        txtSysLog.Text = string.Format("Zalogowny jako: {0}\nID: {1}\nZamknij dialog i kliknij zaloguj!", User_FirstName, ID);
                    }
                    else
                    {
                        txtSysLog.Text = "Bledne haslo lub email!";
                    }

                    reader.Close();
                }
            }
            catch (MySqlException ex)
           {
              txtSysLog.Text = ex.ToString();
           }
            finally
            {
                con.Close();
            }

All replies (8)

Sunday, November 20, 2016 10:51 AM âś…Answered

Disabling Linker is fixing the issue.

If something works in Debug mode but does not in Release mode then most likely the issue is that the Linker is not including your dll when it generates the Release binary.

If you double click on your Android project in the Solution Explorer you can change the setting under Build -> Android Build.

You'll need to select Release for your configuration and then select the Linker tab. If you select "Don't Link" all dlls your project reference will be include in the Release binary. This will lead to a larger binary size but will help you diagnose if this it the problem.

You can read more about the Linker from the Xamarin docs: https://developer.xamarin.com/guides/ios/advanced_topics/linker/

http://stackoverflow.com/questions/35521878/same-android-app-who-runs-on-debug-mode-crashes-on-release-mode


Sunday, November 20, 2016 10:27 AM

Can be a permission problem in manifest?


Sunday, November 20, 2016 10:34 AM

When I am commenting line with con.Close();

errors does not occur.

Any idea how to fix that?


Sunday, November 20, 2016 10:35 AM

Alessandro Which permission should I add then? That what I do know we need Internet access to connect, something more?

there is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="DziennikTreningowy.BartusZak" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="Dziennik Treningowy" android:icon="@drawable/Icon"></application>
    <uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
    <uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" />
</manifest>

Sunday, November 20, 2016 10:50 AM

It should be enough.

I have found this.

https://gist.github.com/cofearabi/5039135

There should be some problem if you don't use an IP address... try to change your http address to an IP address

Then, you could try not to open and close your connection at every query. Open the first time then reopen if it is necessary


Tuesday, December 10, 2019 12:21 AM

I have the same problem, and I can't solve it, I don't know where the error is, I have the manifest as you do, in debug mode it works ok, but not in release.


Tuesday, December 10, 2019 10:50 PM

i need help ! plz!


Friday, December 13, 2019 12:19 PM

I have same prob with you @daviten74
Most research Ive made, they suggest to use REST service