Question: I caņ't seem to get around this error message: ExecuteNonQuery: Connection property has not been initialized

It refers to a `cmd.ExecuteNonQuery();`
I'm not really sure what is going on, maybe the insert is not correct, but here is my code:

```
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace md2
{
public partial class Form2 : Form
{
    SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=MD2;Integrated Security=True;Pooling=False");
    SqlCommand cmd = new SqlCommand();
    SqlDataReader dr;
    public Form2()
    {
        InitializeComponent();
    }

    private void label2_Click(object sender, EventArgs e)
    {
        cmd.Connection = cn;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (izd_adr.Text != "" && izd_nos.Text != "") {
            cn.Open();               
            cmd.CommandText = "insert into Publisher (pu_id, pub_name, adress) values ("+null+"'Elina', 'Kalnina')";
            cmd.ExecuteNonQuery();
            cmd.Clone();
            MessageBox.Show("Ir pievienots");
            cn.Close();
            new Form1().Show();
        }
    }
}
}

```

I followed a tutorial in how to do this, but I'm getting this error.
That Database looks like this: [![enter image description here](https://i.stack.imgur.com/pqLFv.png)](https://i.stack.imgur.com/pqLFv.png)

This seems like a easy mistake somewhere, but is really frustrating...

Answer: 
1: Use an IntentService to do your downloads. 

<http://developer.android.com/reference/android/app/IntentService.html>

2: Set up your IntentService using AlarmManager so that it runs even if the
 application is not running. You register with the AlarmManager 

<http://developer.android.com/reference/android/app/AlarmManager.html>

There are a variety of ways you can have the AlarmManager start your 
 intent.

For Example:
 // Register first run and then interval for repeated cycles.
 alarmManager.setInexactRepeating(AlarmManager.ELAPSED\_REALTIME\_WAKEUP,
 SystemClock.elapsedRealtime() + DEFAULT\_INITIAL\_RUN,
 DEFAULT\_RUN\_INTERVAL, pi);

3: Storing Data
 There are several options here depending on how public you want your
 pictures/data to be.

<http://developer.android.com/reference/android/os/Environment.html>

Example: External Public Storage
 File dirBackup = Environment.getExternalStoragePublicDirectory(
 "YourDirectory" );

4: Downloading

Your option here. You can using anything from your current API to a 
 basic URLConnection.

You may want to look at: 

```
http://developer.android.com/reference/android/app/DownloadManager.html

```

Also, watch your permissions you will need to add 

and

Hope this points you in a useful direction.
The important things to think about here is 

`Thread` , `Service` ,`File` , `Json`, `Context`,`Receiver` & `if else` & `for`

maybe i did not understand your question but this is not a big deal sir,
your programm your app to work in way where your app starts when the os broadcast `onBootCompleted`, then create a `Thread` where you are going to do a lot of code - getting your json file-(when you need it), since its an array you get your `jsonObject` images, whether its a thousand or million you just iterate it and use any approach to download it, i'd say use the traditional way of downloading your images so as you better control it. 
With the help of `File` class you save it alongside `Context` you can get your app's cache's directory, which is an internal memory save it there and create a column in your database where you can save the path to the file in your database as String.

When your app start in `onPrepareOptionsMenu()` check if your app's cache's directory is empty-if not you have some files, now since you have every file and its respective path you can check if it exists with `File.exist()` if it does no need to download.

if you need pace you can always create new Threads. The `Reciever` was to be the guy who gets notified when your device boots, if else for a lot of logic checking, `for` for your loopings, Service to be able to do long running work and have a way to communicate between the UI and background thread.

*sorry for the last paragraph i was just trying to buy space :)*