---
title: "ExecuteNonQuery: Connection property has not been initialized."  
description: "ExecuteNonQuery: Connection property has not been initialized."  
author: "Tarun Kumar"  
published: 2016-02-23  
updated: 2016-02-23  
canonical: https://www.mindstick.com/forum/33992/executenonquery-connection-property-has-not-been-initialized  
category: "c#"  
tags: ["c#", ".net", "sql server", "sql"]  
reading_time: 1 minute  

---

# ExecuteNonQuery: Connection property has not been initialized.

I am [getting error](https://www.mindstick.com/forum/159638/getting-error-microsoft-office-interop-outlook-doesn-t-work) "[ExecuteNonQuery](https://answers.mindstick.com/qa/116279/explain-the-executenonquery-executescalar-and-executereader-methods-of-the-command-object): [Connection](https://www.mindstick.com/articles/13012/what-makes-ethernet-connection-better-than-wifi) [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) has not been initialized." while executing [command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) in C#.\

```
SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "My Insert Query";
                cmd.ExecuteNonQuery();
```

Please help

## Replies

### Reply by Uttam Misra

You forgot to assign connection to the **SqlCommand**, you can use the **constructor** or **property**use following line of code\

```
SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandText = "My Insert Query";
                cmd.ExecuteNonQuery();
```

\


---

Original Source: https://www.mindstick.com/forum/33992/executenonquery-connection-property-has-not-been-initialized

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
