473,396 Members | 1,815 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,396 software developers and data experts.

ExecuteReader: Connection property not initialized

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 request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: ExecuteReader:
Connection property has not been initialized.

Source Error:
Line 25: oConnection.Open()
Line 26: comd = New SqlCommand("select naam,type from pc")
Line 27: dtreader = comd.ExecuteReader
Line 28: x = 0
Line 29: If dtreader.HasRows Then
Source File: D:\Inetpub\wwwroot\aspnet\Begin\Chapter07\access2. aspx Line:
27
--------------------------------------------------------------
My code:
Dim oConnection As System.Data.OleDb.OleDbConnection
oConnection = New System.Data.OleDb.OleDbConnection()

Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim x As Integer

Dim sConnectionString As String
sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
= d:\access\nemi.mdb"
oConnection.ConnectionString = sConnectionString

oConnection.Open()
comd = New SqlCommand("select name,type from pc")
dtreader = comd.ExecuteReader
x = 0
If dtreader.HasRows Then
While dtreader.Read
x = x + 1
Response.Write(dtreader.Item("naam"))
Response.Write("<br>")
End While
End If
Response.Write(x)
dtreader.Close()
oConnection.Close()
Thanks
Phil
May 8 '06 #1
4 4037
You need to assign the Connection oject to the Command object:

comd = New SqlCommand("select name,type from pc", oConnection)

May 8 '06 #2
Hi, thanks for replying.
I forgot it indeed (i'm new to this).

But now, i get another error:
Compiler Error Message: BC30311: Value of type
'System.Data.OleDb.OleDbConnection' cannot be converted to
'System.Data.SqlClient.SqlConnection'.

Source Error:
Line 23: ' Ouverture de la connexion
Line 24: oConnection.Open()
Line 25: comd = New SqlCommand("select name,type from
pc",oConnection)
Line 26: dtreader = comd.ExecuteReader
Line 27: x = 0

Source File: D:\Inetpub\wwwroot\aspnet\Begin\Chapter07\access2. aspx Line:
25
This is in the beginning of the code:
<%@ Page Language="VB" %>
<%@ import namespace="System.Data"%>
<%@ import namespace="System.Data.SqlClient"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
....

Thanks again
Phil
May 8 '06 #3
You can't use an OleDbConnection with an SqlCommand. You have to use the
objects that fit together.

OleDbConnection
OleDbCommand
OleDbDataReader

or

SqlConnection
SqlCommand
SqlDataReader
phil wrote:
Hi, thanks for replying.
I forgot it indeed (i'm new to this).

But now, i get another error:
Compiler Error Message: BC30311: Value of type
'System.Data.OleDb.OleDbConnection' cannot be converted to
'System.Data.SqlClient.SqlConnection'.

Source Error:
Line 23: ' Ouverture de la connexion
Line 24: oConnection.Open()
Line 25: comd = New SqlCommand("select name,type from
pc",oConnection)
Line 26: dtreader = comd.ExecuteReader
Line 27: x = 0

Source File: D:\Inetpub\wwwroot\aspnet\Begin\Chapter07\access2. aspx Line:
25
This is in the beginning of the code:
<%@ Page Language="VB" %>
<%@ import namespace="System.Data"%>
<%@ import namespace="System.Data.SqlClient"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...

Thanks again
Phil

May 10 '06 #4
Yes, you are right ..
Thanks

"Göran Andersson" <gu***@guffa.com> wrote in message
news:OR**************@TK2MSFTNGP03.phx.gbl...
You can't use an OleDbConnection with an SqlCommand. You have to use the
objects that fit together.

OleDbConnection
OleDbCommand
OleDbDataReader

or

SqlConnection
SqlCommand
SqlDataReader
phil wrote:
Hi, thanks for replying.
I forgot it indeed (i'm new to this).

But now, i get another error:
Compiler Error Message: BC30311: Value of type
'System.Data.OleDb.OleDbConnection' cannot be converted to
'System.Data.SqlClient.SqlConnection'.

Source Error:
Line 23: ' Ouverture de la connexion
Line 24: oConnection.Open()
Line 25: comd = New SqlCommand("select name,type from
pc",oConnection)
Line 26: dtreader = comd.ExecuteReader
Line 27: x = 0

Source File: D:\Inetpub\wwwroot\aspnet\Begin\Chapter07\access2. aspx Line: 25
This is in the beginning of the code:
<%@ Page Language="VB" %>
<%@ import namespace="System.Data"%>
<%@ import namespace="System.Data.SqlClient"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...

Thanks again
Phil

May 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
1
by: fniles | last post by:
I am using OLEDBDataReader to read from an Access database. I have 4 data source where I get my data from, and each data source is in its own thread. When receiving data, if it is a new...
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...
2
by: Martin Z | last post by:
I'm using the TableAdapterHelper to set the connection and transaction properties on all the commands of all my typed table adapters.... I've checked at the time of the error and all the commands...
7
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get...
2
by: gggram2000 | last post by:
Hi, I'm using visual studio 2005 with sql server 2005. I made a program on my computer that works great. I wanted to transfer the same project through a remote connection to another computer, I...
2
by: murugavelmsc | last post by:
Hi, In Visual studio 2008, i got a error "ExecuteReader: Connection property has not been initialized" . So guide me protected void Button1_Click(object sender, EventArgs e) { ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.