Newbie Question (kinda)

I am attempting to open a connection to a SQL 2000 Server in VB 2005 Express, and I am receiving an InvalidOperationException. I can't seem to figure it out as my VB.NET is a little weak...

Here's the code:

Dim con As New OleDb.OleDbConnection("PROVIDER=SQLOLEDB; packet size=4096;user id=BLAH;data source=SOMESERVER;persist security info=False;database=BooBoo")

Dim cmd As New OleDb.OleDbCommand("Select Customer.CustomerID as vCustomerID, Customer.FirstName as vCustomerFirstName, Customer.LastName as vCustomerLastName, Customer.CompanyIDNum as vCompanyIDNum, Customer.Zip as vCustomerZip, Installation.InstallationID as vInstallationID, Installation.Status as vInstallationStatus, Installation.RecieveSignalLevel as vInstallationRSL, Installation.HWType as vInstallationHW from Customer INNER JOIN Installation ON Customer.CustomerID = Installation.CustomerID Where Installation.Status = 'pending'")

Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader()

If reader.Read() Then

vpCustomerID = reader("vCustomerID").ToString

vpCustomerFirstName = reader("vCustomerFirstName").ToString

vpCustomerLastName = reader("vCustomerLastName").ToString

vpCustomerCompanyID = reader("vCompanyIDNum").ToString

vpCustomerZip = reader("vCustomerZip").ToString

vpInstallationID = reader("vInstallationID").ToString

vpInstallationStatus = reader("vInstallationStatus").ToString

vpInstallationRSL = reader("vInstallationRSL").ToString

vpInstallationHWType = reader("vInstallationHW").ToString

End If

any help would be greatly appreciated!

Jeremy



Answer this question

Newbie Question (kinda)

  • SanJain

    Jeremy_Ward wrote:

    Dim con As New OleDb.OleDbConnection("PROVIDER=SQLOLEDB; packet size=4096;user id=BLAH;data source=SOMESERVER;persist security info=False;database=BooBoo")

    Dim cmd As New OleDb.OleDbCommand("Select Customer.CustomerID as vCustomerID, Customer.FirstName as vCustomerFirstName, Customer.LastName as vCustomerLastName, Customer.CompanyIDNum as vCompanyIDNum, Customer.Zip as vCustomerZip, Installation.InstallationID as vInstallationID, Installation.Status as vInstallationStatus, Installation.RecieveSignalLevel as vInstallationRSL, Installation.HWType as vInstallationHW from Customer INNER JOIN Installation ON Customer.CustomerID = Installation.CustomerID Where Installation.Status = 'pending'")

    You can better use SQL Client namespace for connecting to SQL

    Jeremy_Ward wrote:

    Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader()

    If reader.Read() Then

    vpCustomerID = reader("vCustomerID").ToString

    vpCustomerFirstName = reader("vCustomerFirstName").ToString

    vpCustomerLastName = reader("vCustomerLastName").ToString

    vpCustomerCompanyID = reader("vCompanyIDNum").ToString

    vpCustomerZip = reader("vCustomerZip").ToString

    vpInstallationID = reader("vInstallationID").ToString

    vpInstallationStatus = reader("vInstallationStatus").ToString

    vpInstallationRSL = reader("vInstallationRSL").ToString

    vpInstallationHWType = reader("vInstallationHW").ToString

    End If

    any help would be greatly appreciated!

    Jeremy

    I think that one of your values maybe DBNull.Value. Can you post the query result

    You can also place a breakpoint the first line of your routine and see wich line of code generates the error.



  • KLC

    use :

    Dim cmd As New OleDb.OleDbCommand("Select Customer.CustomerID as vCustomerID, Customer.FirstName as vCustomerFirstName, Customer.LastName as vCustomerLastName, Customer.CompanyIDNum as vCompanyIDNum, Customer.Zip as vCustomerZip, Installation.InstallationID as vInstallationID, Installation.Status as vInstallationStatus, Installation.RecieveSignalLevel as vInstallationRSL, Installation.HWType as vInstallationHW from Customer INNER JOIN Installation ON Customer.CustomerID = Installation.CustomerID Where Installation.Status = 'pending'", conn)



  • Wenbin Zhang

    Thou areth completely correct!

  • tseiy

    con.Open( ) is Missing
     
    Regards
    Jignesh Desai

    I am attempting to open a connection to a SQL 2000 Server in VB 2005 Express, and I am receiving an InvalidOperationException. I can't seem to figure it out as my VB.NET is a little weak...

    Here's the code:

    Dim con As New OleDb.OleDbConnection("PROVIDER=SQLOLEDB; packet size=4096;user id=BLAH;data source=SOMESERVER;persist security info=False;database=BooBoo")

    Dim cmd As New OleDb.OleDbCommand("Select Customer.CustomerID as vCustomerID, Customer.FirstName as vCustomerFirstName, Customer.LastName as vCustomerLastName, Customer.CompanyIDNum as vCompanyIDNum, Customer.Zip as vCustomerZip, Installation.InstallationID as vInstallationID, Installation.Status as vInstallationStatus, Installation.RecieveSignalLevel as vInstallationRSL, Installation.HWType as vInstallationHW from Customer INNER JOIN Installation ON Customer.CustomerID = Installation.CustomerID Where Installation.Status = 'pending'")

    Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader()

    If reader.Read() Then

    vpCustomerID = reader("vCustomerID").ToString

    vpCustomerFirstName = reader("vCustomerFirstName").ToString

    vpCustomerLastName = reader("vCustomerLastName").ToString

    vpCustomerCompanyID = reader("vCompanyIDNum").ToString

    vpCustomerZip = reader("vCustomerZip").ToString

    vpInstallationID = reader("vInstallationID").ToString

    vpInstallationStatus = reader("vInstallationStatus").ToString

    vpInstallationRSL = reader("vInstallationRSL").ToString

    vpInstallationHWType = reader("vInstallationHW").ToString

    End If

    any help would be greatly appreciated!

    Jeremy


  • Ben Ogle

    The quey works appropriately in Query Analayzer and produces the intended result.

    I placed con.Open() above the read. I am still getting the same error.

    InvalidOperationsException. ExecuteReader: Connection property has not been initialized.

    J


  • Newbie Question (kinda)