Re: .Net/SQL Drop Table Problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Set the SqlCommand's Connection property before executing the query.

"The VanDerbeck Group" <TheVanDerbeckGroup@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:350B75F1-9BDA-4E02-BAB6-901D98741769@xxxxxxxxxxxxxxxx
The code below generates the indicated error. As a newbie to vb and SQL I
have no idea how to track this down. I did verify that the connection state
is open. My suspicion is that I have to connect to a seperate "sysobjects"
database???

THE CODE:

Dim oSQLConnection As New SqlConnection("data source =" _
& "psi-sbs2k3 ;" _
& "initial catalog = 'JHH PRODUCT DATA' ;" _
& "Integrated Security=SSPI;" _
& "persist security info =True;")
oSQLConnection.Open()

Dim osqlCommand As New SqlCommand("if exists (select * from
dbo.sysobjects where id = object_id(N'[dbo].[dsdprod]') and
OBJECTPROPERTY(id, N'IsUserTable') = 1)" _
& " drop table [dbo].[dsdprod] ")
osqlCommand.ExecuteNonQuery()

ERROR GENERATED IS...

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.data.dll

Additional information: ExecuteNonQuery: Connection property has not been
initialized.


.



Relevant Pages

  • Re: Connection Property error
    ... I was in the Form view and I notice that the cmdStores Connection Property ... Dim drStores As SqlClient.SqlDataReader ... cmdStores object prior to executing this line drStores = ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: IDE no response
    ... it happens only to TADO components, ... if I put TDOTable onto a form, set the connection property, then select ... SQL statement, click OK, it was frozen. ... It has no problem with BDE VCL I tried. ...
    (borland.public.delphi.database.ado)
  • Re: MS Query - From in SQL
    ... In addition to updating the Connection property to update the DB command ... which should contain the SQL query. ...
    (microsoft.public.excel.programming)
  • Re: Embedded SP
    ... A second option is to set the connection property ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.sqlserver.programming)