There was an error Parsing the Query. [Token Line number = 1, Token Line offset =1, Token in error = 1 ].

arulkumarske
arulkumarske used Ask the Experts™
on
I am Using SqlcedataReader in Sql server Compact Edition 3.5, but when the application runs the Execute reader Method. It is throwing the error message as There was an error Parsing the Query. [Token Line number = 1, Token Line offset =1, Token in error = 1 ]. If i execute the query in Management Studio it is working.  If any body knows the answer request to help me in this regards,

Regards,
Arul Kumar
sSql = "SELECT * From TMOBIHUBCE;"
            cmdSKU = New SqlCeCommand(sSql, oNewConnection)
            cmdSKU.CommandText = CommandType.Text
            rdrReadSKU = cmdSKU.ExecuteReader(CommandBehavior.Default)

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
can you please try this one?

sSql = "SELECT * From TMOBIHUBCE"
cmdSKU = New SqlCeCommand(sSql, oNewConnection)
cmdSKU.CommandText = CommandType.Text
rdrReadSKU = cmdSKU.ExecuteReader()

Author

Commented:
Hi Ritesh,
Still Same Error Persists, Attached the Changed Code for reference. Request to help me in this regards.
Regards,
Arul Kumar


sSql = "SELECT * From TMOBIHUBCE"
            cmdSKU = New SqlCeCommand(sSql, oNewConnection)
            cmdSKU.CommandText = CommandType.Text
            rdrReadSKU = cmdSKU.ExecuteReader()

Open in new window

this error is popular error and used to come when you have something wrong in SQL Syntax but in your case I can't find any wrong syntax, are you using the same code? or it is a part of bigger query?
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Author

Commented:
Hi Ritesh,

1. This is the Query i am using. There will be always only record only.
Request to help me in this regards.

Thanks in Advance.
Regards,
Arul Kumar.


AneeshDatabase Consultant
Top Expert 2009
Commented:
Hello arulkumarske,

sSql = "SET NOCOUNT ON ; SELECT * From dbo.TMOBIHUBCE"
            cmdSKU = New SqlCeCommand(sSql, oNewConnection)
            cmdSKU.CommandText = CommandType.Text
            rdrReadSKU = cmdSKU.ExecuteReader()


Regards,

Aneesh
can you please post your full code? I just wanted to sure whether you are missing something. moreover, can you try by using field name instead of "*" in query? I know this is not a solution but just give it a try.

Author

Commented:
Hi ritesh,

1. Attached the Code Snippet, request to help me in this regards,

Arul Kumar
    Private Sub BCRReceive_BarcodeRead(ByVal sender As System.Object, ByVal bre As Intermec.DataCollection.BarcodeReadEventArgs) Handles BCRReceive.BarcodeRead
        Dim rdrReadSKU As SqlCeDataReader = Nothing
        Dim sDeviceName As String = System.Net.Dns.GetHostName()
        Dim oNewConnection As SqlCeConnection = Nothing
        Dim ceEng As SqlCeEngine = Nothing
        Dim iQty As Integer = 0
        Dim sBatchCode As String = String.Empty
        'Code For Reading Barcode and Fetch the SKU Details
        Dim sConnectionString As String = "Data Source= " + GetAppPath() + "\MOBIHUB.sdf;"
 
        Try
            txtSKU.Text = bre.strDataBuffer.ToString
            Dim sSql As String = String.Empty
            Dim sActCode As String = String.Empty
            Dim cmdSKU As SqlCeCommand
 
            sConnectionString = "Data Source= " + GetAppPath() + "\MOBIHUB.sdf;"
            oNewConnection = New SqlCeConnection(sConnectionString)
            oNewConnection.Open()
            sSql = "SELECT * From TMOBIHUBCE"
            cmdSKU = New SqlCeCommand(sSql, oNewConnection)
            cmdSKU.CommandText = CommandType.Text
            rdrReadSKU = cmdSKU.ExecuteReader()
            While rdrReadSKU.Read
                rdrReadSKU.Read()
                sBatchCode = rdrReadSKU.GetValue(2)
                iQty = rdrReadSKU.GetValue(3)
                txtBatchCode.Text = sBatchCode
                txtPUOMQty.Text = iQty
            End While
            If rdrReadSKU.IsClosed = False Then
                rdrReadSKU.Close()
                rdrReadSKU.Dispose()
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
            '            ManageMobileHub.cManageLogs.ManageLogs(System.Guid.NewGuid.ToString, ex.ToString)
        Finally
            oNewConnection.Close()
        End Try
    End Sub
 
 
 
        Public Shared Function GetAppPath() As String
            Dim fullPath As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
            GetAppPath = fullPath
        End Function

Open in new window

Author

Commented:
hI aneeshattingal

I have tried set nocount on: it is throwing the same error. I am using Sqlce 3.5, .NET Compact Framework 2.0 SP2 and VS 2005. Request ot help me in this regards, Attached Code Reference

Regards,
Arul Kumar.
Private Sub BCRReceive_BarcodeRead(ByVal sender As System.Object, ByVal bre As Intermec.DataCollection.BarcodeReadEventArgs) Handles BCRReceive.BarcodeRead
        Dim rdrReadSKU As SqlCeDataReader = Nothing
        Dim sDeviceName As String = System.Net.Dns.GetHostName()
        Dim oNewConnection As SqlCeConnection = Nothing
        Dim ceEng As SqlCeEngine = Nothing
        Dim iQty As Integer = 0
        Dim sBatchCode As String = String.Empty
        'Code For Reading Barcode and Fetch the SKU Details
        Dim sConnectionString As String = "Data Source= " + GetAppPath() + "\MOBIHUB.sdf;"
 
        Try
            txtSKU.Text = bre.strDataBuffer.ToString
            Dim sSql As String = String.Empty
            Dim sActCode As String = String.Empty
            Dim cmdSKU As SqlCeCommand
 
            sConnectionString = "Data Source= " + GetAppPath() + "\MOBIHUB.sdf;"
            oNewConnection = New SqlCeConnection(sConnectionString)
            oNewConnection.Open()
            sSql = "SELECT * From TMOBIHUBCE"
            cmdSKU = New SqlCeCommand(sSql, oNewConnection)
            cmdSKU.CommandText = CommandType.Text
            rdrReadSKU = cmdSKU.ExecuteReader()
            While rdrReadSKU.Read
                rdrReadSKU.Read()
                sBatchCode = rdrReadSKU.GetValue(2)
                iQty = rdrReadSKU.GetValue(3)
                txtBatchCode.Text = sBatchCode
                txtPUOMQty.Text = iQty
            End While
            If rdrReadSKU.IsClosed = False Then
                rdrReadSKU.Close()
                rdrReadSKU.Dispose()
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
            '            ManageMobileHub.cManageLogs.ManageLogs(System.Guid.NewGuid.ToString, ex.ToString)
        Finally
            oNewConnection.Close()
        End Try
    End Sub
 
 
 
        Public Shared Function GetAppPath() As String
            Dim fullPath As String = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
            GetAppPath = fullPath
        End Function

Open in new window

Author

Commented:
at last i have found the Solution for it. The Solution is That the Change the Declarations to the top of the Function and Put te ssql above the connection Initialization.  Then it works. I don't know it is the reason. but any how it works.  Thank you very much for all who posted the comments and give me the suggestions.

Thanks & regards,
Arul Kumar

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial