InvalidOperationException on Pocket PC 2003 from SQLClient

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

Hey Guys:
I'm getting a "System.InvalidOperationException: Application-defined
or object defined error" message when I try to do any operations with
a SQLClient variable. I've used this on Pocket PC 2002 before
successfully, I don't know what's going on. Here's the code
snippet...very simple. And I have copied the System.Data.SqlClient and
other libraries out to the PDA. Very strange, any help is appreciated.
It throws the error on the cmd.ExecuteScalar line.

Thanks in advance.

-Jason
--------------------------------------------------------------

Private Sub HandleData2()
Dim SQL As String
Dim con As New SqlConnection("Password=xxxx;User
ID=xxx;Initial Catalog=xxx;Data Source=xxx")
Dim cmd As New SqlCommand
Dim location As String
Try
SQL = "SELECT PaperFileLocation FROM PaperFileLocations
WHERE PaperFileLocationID = 1025"

cmd.Connection = con
cmd.CommandText = SQL
location = cmd.ExecuteScalar()

MessageBox.Show(location)
Catch sqlErr As SqlException
MessageBox.Show("SQL Error: " & sqlErr.ToString)
Catch ioErr As InvalidOperationException
MessageBox.Show("IO Error: " & ioErr.ToString)
Catch otherErr As Exception
MessageBox.Show("Error: " & otherErr.ToString)
End Try
End Sub
---------------------------------------------------------------
 
I just tried that exact code with a slightly different SQL statement:

sql = "SELECT LastName FROM Employees WHERE EmployeeID = 2";



With the Northwind database (and C#, obviously). It works fine. Could it
be that the user name you've used is not authorized to perform this action?
Could you set a breakpoint on the exception case where it's stopping and
further get into the exception for us?



Paul T.
 
It doesn't look like you're opening your connection before attempting to
execute commands on it. Can you try adding a con.Open before your execute?
 
Back
Top