Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello ,
i am working with NhiberNate and VB.NET
i am getting "could not execute Query" error in my applicaion.
my code is as follows.
Public Function GetTicketStatus(ByVal tkt As String) As String
            Try
                Dim strQuery As String = "Select stat from tkt where tkt = '" & tkt & "'"
                Dim resultData = GetISession.CreateSQLQuery(strQuery).List()
                If resultData IsNot Nothing AndAlso resultData.Count > 0 Then
                    Return resultData(0).ToString()
                Else
                    Return String.Empty
                End If
            Catch ex As Exception
                
            End Try
        End Function

The stack Trace is as follows
Message: could not execute query
[ Select stat from tkt where tkt =  = '12345' ] [SQL: Select stat from tkt where tkt =  = '12345']
Stack Trace :
   at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in E:\sources\NHibernate\src\NHibernate\Loader\Loader.cs:line 1660
   at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in E:\sources\NHibernate\src\NHibernate\Loader\Loader.cs:line 1575
   at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in E:\sources\NHibernate\src\NHibernate\Loader\Loader.cs:line 1569
   at NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor session, QueryParameters queryParameters) in E:\sources\NHibernate\src\NHibernate\Loader\Custom\CustomLoader.cs:line 272
   at NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) in E:\sources\NHibernate\src\NHibernate\Impl\SessionImpl.cs:line 2107
   at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results) in E:\sources\NHibernate\src\NHibernate\Impl\SessionImpl.cs:line 2090
   at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters) in E:\sources\NHibernate\src\NHibernate\Impl\SessionImpl.cs:line 2066
   at NHibernate.Impl.SqlQueryImpl.List() in E:\sources\NHibernate\src\NHibernate\Impl\SqlQueryImpl.cs:line 127
   at BusinessClasses.TicketHeaderBll.GetTicketStatus(String tkt) in J:\BusinessClasses\TicketHeaderBll.vb:line 4803
Inner Exception :  - Object reference not set to an instance of an object.

in inner exception it is "Object reference not set to an instance of an object" .
with my database and in my machine it is correctly working.but in rare situations this is coming.
any one can explain please how to resolve it.
Posted
Updated 28-Nov-13 0:19am
v6
Comments
[no name] 28-Nov-13 5:57am    
can you share some data of the table..?
pullareddy S 28-Nov-13 6:07am    
primkey tkt stat tktdate
1 12345 V 06/19/2013 12:00:00 AM
2 12346 C 06/19/2013 12:00:00 AM
3 12347 C 06/19/2013 12:00:00 AM
hi , i am giving some fields of data here i want "stat" column in my query.

The error may occur in case table does not contain rows for some conditions.
 
Share this answer
 
Comments
pullareddy S 28-Nov-13 6:12am    
HI,
I tried with invalid tkt .in that there is no rows.
but i am getting list with count = 0.
and there is no error is coming here
"Dim resultData = GetISession.CreateSQLQuery(strQuery).List()"
Thanks.
There could be several reasons:

  1. Table tkt doesnt' exists
  2. Field tkt doesn't exists
  3. Field tkt is numeric data type (not varchar)


Please check the name of table and field (NOTE: in a subject you have used table name: 'Table1' instead 'tkt').
If tkt field is numeric data typ , you should write query in that way:
SQL
SELECT [stat]
FROM Table1 where tkt = 1234
 
Share this answer
 
Comments
pullareddy S 28-Nov-13 6:18am    
Hi,
in my table tkt field exist,and it is char type(FoxPro).but i will check with deleting table.(but if table or column doesnot exist,i think we will get other message like table not exist.etc )
Thanks ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900