Results 1 to 24 of 24

Thread: [RESOLVED] [2005] Oracle Select Query Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Resolved [RESOLVED] [2005] Oracle Select Query Problem

    Hi, I am trying to pull data from an Oracle table using a Select query with a Where clause. When the Where clause contains 4 or less characters, it works fine. When I try something with more that 4, it won't pull anything. I have verified the data is actually in the table, and have tried hardcoded the criteria with no success. Any suggestions? thanks!

    VB Code:
    1. Dim objcommand As New OracleCommand("SELECT * FROM APP_SECURITY WHERE APP_SECURITY.USER_NAME = 'test1'", objConnection)

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Oracle Select Query Problem

    Couple of questions,

    What is tha MaxSize of the USER_NAME Field?
    What Is the error that you are getting?
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    Hi,

    The size is set at 8, and I am not trying anything longer than that.
    There is no actual error message, it just doesn't return anything when > 4 characters. Here is the code i am using to evaluated the results:
    VB Code:
    1. objDataReader = objcommand.ExecuteReader()
    2.         If objDataReader.HasRows Then
    3.             objDataReader.Read()
    4.             MsgBox(objDataReader.Item(0))
    5.         Else
    6.             MsgBox("nuttin")
    7.         End If

  4. #4
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Oracle Select Query Problem

    is the user name test1 in the database?
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    yes it is. i've tried other ones too that are in there...even copied directly from the database and no luck.

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    Is the username in test1 in the same case? To Oracle test1 and Test1 are two different things.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    Gary- Yes it is, I tried several others too copying directly from the tables.

  8. #8
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Oracle Select Query Problem

    Can you post your complete code from this procedure
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    VB Code:
    1. Private Sub cmdLogin_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
    2.         Me.APP_SECURITY1TableAdapter.Fill(Me.DataSet2.APP_SECURITY)
    3.  
    4.         'Initialize the Connection object
    5.         objConnection = New OracleConnection(strConnectionString)
    6.         objConnection.Open()
    7.  
    8.         Dim objcommand As New OracleCommand("SELECT * FROM APP_SECURITY WHERE APP_SECURITY.USER_NAME = '" & Me.txtID.Text & "'", objConnection)
    9.  
    10.         objDataAdapter = New OracleDataAdapter
    11.         objDataAdapter.SelectCommand = objcommand
    12.  
    13.         'Initialize the DataTable object
    14.         objDataTable = New DataTable
    15.  
    16.         'Populate the DataTable
    17.         objDataAdapter.Fill(objDataTable)
    18.  
    19.  
    20.         'Execute the query
    21.         objDataReader = objcommand.ExecuteReader()
    22.         If objDataReader.HasRows Then
    23.             objDataReader.Read()
    24.             MsgBox(objDataReader.Item(0))
    25.         Else
    26.             MsgBox("nuttin")
    27.         End If
    28.         objcommand.Dispose()
    29.         objcommand = Nothing
    30.         objDataAdapter.Dispose()
    31.         objDataAdapter = Nothing
    32.         objDataTable.Dispose()
    33.         objDataTable = Nothing
    34.         objConnection.Close()
    35.  
    36.         'Clean up  
    37.  
    38.         objcommand = Nothing
    39.         objConnection.Dispose()
    40.         objConnection = Nothing
    41.  
    42.     End Sub

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    This is what I use to login to a DB:

    VB Code:
    1. Dim bConnected As Boolean = False
    2.         Dim strConn As String
    3.         Dim oConn As System.Data.OracleClient.OracleConnection
    4.         Dim oCmd As System.Data.OracleClient.OracleCommand
    5.         Dim oDr As System.Data.OracleClient.OracleDataReader
    6.         Dim strSQL As String = "SELECT * FROM APP_SECURITY WHERE APP_SECURITY.USER_NAME = '" & Me.txtID.Text.replace("'","''").Trim() & "'"
    7.  
    8.         strConn = mdlDatabase.BuildConnString()
    9.         Try
    10.             oConn = New System.Data.OracleClient.OracleConnection(strConn)
    11.             oConn.Open()
    12.             bConnected = True
    13.  
    14.             If bConnected = True Then
    15.  
    16.                 oCmd = New System.Data.OracleClient.OracleCommand
    17.                
    18.                 With oCmd
    19.                     .Connection = oConn
    20.                     .CommandType = CommandType.Text
    21.                     .CommandText = strSQL
    22.                     oDr = .ExecuteReader(CommandBehavior.SingleRow)
    23.                 End With
    24.                 if oDR.HasRows
    25.                     oDR.Read()
    26.                     MsgBox(oDR.Item(0).ToString()
    27.                 else
    28.                     MsgBox("Problem with Select!" & system.enviorment.newline & strSQL)
    29.                 end if
    30.                
    31.             End If
    32.  
    33.         Catch exSQL As System.Data.OracleClient.OracleException
    34.             MessageBox.Show("There was an error with the database." & System.Environment.NewLine & _
    35.                             "The error is: " & exSQL.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    36.         Catch ex As Exception
    37.             MessageBox.Show("An unexpected error occured in the application." & System.Environment.NewLine & _
    38.                             "The error is: " & ex.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    39.         Finally
    40.             If Not oCmd Is Nothing Then
    41.                 If Not oDr Is Nothing Then
    42.                     oDr.Close()
    43.                 End If
    44.                 oCmd.Dispose()
    45.             End If
    46.             If Not oConn Is Nothing Then
    47.                 oConn.Close()
    48.                 oConn.Dispose()
    49.             End If
    50.         End Try
    Last edited by GaryMazzone; Sep 21st, 2006 at 12:36 PM.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    I tried this and it works fine with a user_id < 4 characters, but still doesn't work if it's more that 4. It gives the "Problem with Select!" message.

  12. #12
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    Post the exact error message and the exact SQL statemtent that is being sent to the database. The message you say was posted means that the select returned no rows. So I guess I still want to see the exact statemtent being sent to the DB
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    I agree, that's what the error is, I just don't understand why it's working for the shorter strings. Here's the info you requested:

    VB Code:
    1. Dim strSQL As String = "SELECT * FROM APP_SECURITY WHERE APP_SECURITY.USER_NAME = '" & Me.txtID.Text.Replace("'", "''").Trim() & "'"

    The error is the msgbox error "Problem with Select!" from this section:

    VB Code:
    1. If oDr.HasRows Then
    2.                     oDr.Read()
    3.                     MsgBox(oDr.Item(0).ToString())
    4.                 Else
    5.                     MsgBox("Problem with Select!")
    6.                 End If

  14. #14
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    No I want the SQL from the application as it is running. Set a break point after you dim the SQL and fill the string. Then select the strSQL variable and Select the text visualizer and copy and paste the SQL string from there.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    Sorry, I misunderstood. Here it is:

    SELECT * FROM APP_SECURITY WHERE APP_SECURITY.USER_NAME = 'wrightm'

  16. #16
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    I don't know then I use that same post I gave you for returning 'Gary Mazzone' as a user named in a table an have no issues.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    Well I appreciate your help. I will keep trying things and see what happens.

  18. #18
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    Does the select statement work from SQL*Plus?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  19. #19
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: [2005] Oracle Select Query Problem

    Think about using Stored Procedures instead of inline SQL. For one thing, security is an issue. Secondly, the performance is a lot worse using the above code. Third, rights is a big issue with companies, can anyone run that sql? Sure its inline, but sprocs you can assign specific permissions for.

    These are just my suggestions.

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    I figured out why it is happening! Apparently within the database there are multiple schemas. for some reason it is defaulting to a different one than I was looking at. Two of the schemas (or is it scheme?) have an app_security table with some of the same users I was trying. The ones that weren't in the schema I was using just happened to be longer. So...my question now is how can I specify what schema to use?

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    JAKSupport, thanks for the suggestion. I thought since the table I am trying to use is small, I didn't think performance would be a concern. The other points you raised are very good and I will definately give it a try. Thanks!

  22. #22
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    If you have more then one schema the one that will be looked at is the one based on the user name you are loging into the Oracle database as. If you need to look at a table in another scehma then you need rights on the schema.table If you don't have rights you will not get a return. In order to access the table in another schema you can do one of two things.

    1. Create a public synonm for the table (this will cause problems for the other user though).
    2. Fully quallify the path to the table (this would include the schema name infront of the table name).

    PS You will run into the exact same issue with SP's
    Last edited by GaryMazzone; Sep 21st, 2006 at 03:07 PM.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Sep 2006
    Posts
    20

    Re: [2005] Oracle Select Query Problem

    I went with option #2 and it's worked! Thanks again for your help!

  24. #24
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Oracle Select Query Problem

    If this solved your issue pleas mark the thread as resolved
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width