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.InvalidO perationExcepti on: ExecuteReader:
Connection property has not been initialized.
Source Error:
Line 25: oConnection.Ope n()
Line 26: comd = New SqlCommand("sel ect naam,type from pc")
Line 27: dtreader = comd.ExecuteRea der
Line 28: x = 0
Line 29: If dtreader.HasRow s Then
Source File: D:\Inetpub\wwwr oot\aspnet\Begi n\Chapter07\acc ess2.aspx Line:
27
--------------------------------------------------------------
My code:
Dim oConnection As System.Data.Ole Db.OleDbConnect ion
oConnection = New System.Data.Ole Db.OleDbConnect ion()
Dim comd As SqlCommand
Dim dtreader As SqlDataReader
Dim x As Integer
Dim sConnectionStri ng As String
sConnectionStri ng = "Provider = Microsoft.Jet.O LEDB.4.0; Data Source
= d:\access\nemi. mdb"
oConnection.Con nectionString = sConnectionStri ng
oConnection.Ope n()
comd = New SqlCommand("sel ect name,type from pc")
dtreader = comd.ExecuteRea der
x = 0
If dtreader.HasRow s 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.Clo se()
Thanks
Phil 4 4066
You need to assign the Connection oject to the Command object:
comd = New SqlCommand("sel ect name,type from pc", oConnection)
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.Ol eDb.OleDbConnec tion' cannot be converted to
'System.Data.Sq lClient.SqlConn ection'.
Source Error:
Line 23: ' Ouverture de la connexion
Line 24: oConnection.Ope n()
Line 25: comd = New SqlCommand("sel ect name,type from
pc",oConnection )
Line 26: dtreader = comd.ExecuteRea der
Line 27: x = 0
Source File: D:\Inetpub\wwwr oot\aspnet\Begi n\Chapter07\acc ess2.aspx Line:
25
This is in the beginning of the code:
<%@ Page Language="VB" %>
<%@ import namespace="Syst em.Data"%>
<%@ import namespace="Syst em.Data.SqlClie nt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
....
Thanks again
Phil
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.Ol eDb.OleDbConnec tion' cannot be converted to 'System.Data.Sq lClient.SqlConn ection'.
Source Error:
Line 23: ' Ouverture de la connexion Line 24: oConnection.Ope n() Line 25: comd = New SqlCommand("sel ect name,type from pc",oConnection ) Line 26: dtreader = comd.ExecuteRea der Line 27: x = 0
Source File: D:\Inetpub\wwwr oot\aspnet\Begi n\Chapter07\acc ess2.aspx Line: 25
This is in the beginning of the code: <%@ Page Language="VB" %> <%@ import namespace="Syst em.Data"%> <%@ import namespace="Syst em.Data.SqlClie nt"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"> ...
Thanks again Phil
Yes, you are right ..
Thanks
"Göran Andersson" <gu***@guffa.co m> wrote in message
news:OR******** ******@TK2MSFTN GP03.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.Ol eDb.OleDbConnec tion' cannot be converted to 'System.Data.Sq lClient.SqlConn ection'.
Source Error:
Line 23: ' Ouverture de la connexion Line 24: oConnection.Ope n() Line 25: comd = New SqlCommand("sel ect name,type from pc",oConnection ) Line 26: dtreader = comd.ExecuteRea der Line 27: x = 0
Source File: D:\Inetpub\wwwr oot\aspnet\Begi n\Chapter07\acc ess2.aspx
Line: 25
This is in the beginning of the code: <%@ Page Language="VB" %> <%@ import namespace="Syst em.Data"%> <%@ import namespace="Syst em.Data.SqlClie nt"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"> ...
Thanks again Phil
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 Security=SSPI;Initial
Catalog=Northwind;Data Source=SERVER\netsdk"
Dim cnn As New SqlConnection(connstr)
Dim cmd As New SqlCommand
("select * from images where id=" & Request.QueryString("id"), cnn)
cnn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
|
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
oConn.ConnectionString = "Data Source=MyServer;Initial Catalog=TADB;User
Id=TADB;Password=xxx;"
oCmd = New SqlCommand("Exec TA_GetTADetails " & txtTANumber.Text)
oConn.Open()
|
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 exists. I would it to do
this on the fly, if possible. When I execute my current code, I get the
following error:
ExecuteNonQuery: Connection property has not been initialized
Below is the code from the page itself:
-----
|
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 commodity I am need to read from the
database.
Since I can receive data from different data source at the same time, it is
possible that I read from the database at the same time.
|
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 initialized
I cannot see (from inexperience) where I am having the issue.
Many thanks!!!
| |
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 have their
Transaction property set. But I still get this error when I call...
documentTA.Update(documentDS.Document);
"ExecuteReader requires the command to have a transaction when the
connection assigned to the command is in a pending local...
|
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 the
error "ExecuteReader requires an open and available Connection. The
connection's current state is Open, Executing." I do not use ExecuteReader,
why the error says ExecuteReader. What does it mean ?
When I get this error, is there a way for me...
|
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 transfered the debug file with the executable file and everything, I already have the same project on that computer but it was an earlier one I had made so I wanted to update it. The issue was, since I changed my database values, i wanted to transfer the...
|
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)
{
string constr=ConfigurationSettings.AppSettings;
SqlConnection conn = new SqlConnection(constr);
conn.Open();
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |