473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Exception ExecuteReader: Connection property has not been initial

Hi!

I am experiencing a problem when trying to connect to my database.
I keep getting an exception with the following error message:
ExecuteReader: Connection property has not been initial

Here is the code that I am having problems with:

Expand|Select|Wrap|Line Numbers
  1. public List<EmployeeInfo> EmpReadDta()
  2.         {
  3.  
  4.             List<EmployeeInfo> lstemp = new List<EmployeeInfo>();
  5.             try
  6.             {
  7.  
  8.       con.Open();
  9.                SqlCommand cmd = new SqlCommand();
  10.                cmd.CommandText = "procedureReadData";
  11.                cmd.CommandType = CommandType.StoredProcedure;
  12.                 using (SqlDataReader dr = cmd.ExecuteReader())
  13.                 {
  14.                    while (dr.Read())
  15.              {
  16.             EmployeeInfo empI = new EmployeeInfo();
  17.                          empI.UserId = Convert.ToInt32(dr["UserId"]);
  18.                        empI.UserName = Convert.ToString(dr["UserName"]);
  19.                        empI.Address = Convert.ToString(dr["Address"]);
  20.                        empI.EmailAddress = Convert.ToString(dr["EmailAddress"]);
  21.                        empI.Department = Convert.ToString(dr["Department"]);
  22.                         empI.Location = Convert.ToString(dr["Location"]);
  23.                         lstemp.Add(empI);
  24.                     }
  25.  
  26.                 }
  27.  
  28.             }
  29.  
  30.           catch (Exception ex)
  31.         {
  32.              throw ex;
  33.  
  34.           }
  35.  
  36.          return lstemp ;
  37.    }
  38.      }
Thanks!
Apr 9 '11 #1
1 2551
Frinavale
9,735 Expert Mod 8TB
You need to supply a Connection String (a string that contains information about how to connect to the database) to the SqlCommand in order to be able to retrieve data from the database.

-Frinny
Apr 12 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Taishi | last post by:
ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more...
2
by: MattB | last post by:
I'm trying to implement an example I found for displaying images stored in a SQL database. The example code looks like this (in page_load): Dim connstr As String = "Integrated...
2
by: CJM | last post by:
I'm not sure where I cam going wrong here... I'm getting the runtime error above, but my code seems reasonable. Am I missing something? Code Snippet: oConn = New SqlConnection...
3
by: Jason Williard | last post by:
I am trying to create a web form that will be used to create new users. The first step that I am taking is creating a web form that can check the username against a database to see if it already...
4
by: phil | last post by:
Hi, With the code below, i get the error: ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
7
by: Lawrence 007 | last post by:
Hi, I am new to VB.Net and I am trying to create a program that inserts data into a SQL table. Below you will find my code that gives me the following error: Connection Property has not been...
0
by: billy.murray | last post by:
I have a system which comprises 4 servers (1 server per plant area). Each plant area server has 2 databases (Config<nand Runtime<nwhere <nis the plant area number) and 1 web application which uses...
2
by: nada111 | last post by:
SelectCommand.Connection property has not been initialized
1
by: mamtaid | last post by:
i have the following code.... it gives the error::ExecuteReader: Connection property has not been initialized can anyone please help me sst = new DataSet(); asq = new...
0
by: dougancil | last post by:
I have the following code for a web page that I'm working on: Imports System.Data.SqlClient Imports System.Data Partial Class _Default Inherits System.Web.UI.Page Protected Sub...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.