Results 1 to 33 of 33

Thread: Error Sending SQL Command [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90

    Error Sending SQL Command [Resolved]

    I have a SQL Command. This command will change. But the one i am testing with is this.

    Select Distinct c1.Accountno, c1.Company, c1.contact, c1.Phone1 From Contact1 as c1 Inner join Contact2 as c2 On c1.accountno = c2.accountno And c1.U_STATE = 'CA' AND (c1.U_STATE <> 'ON' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'PA' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'CO' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'IL' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'AZ' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'NJ' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'NH' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'AK' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'AL' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'AR' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'BC' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'DE' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'GA' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'IA' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'KS' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'MA' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'MD' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> '' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'OH' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'NS' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'NH' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'NE' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'WI' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'UT' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'TX' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'TN' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'PR' OR c1.U_STATE IS NULL)



    Now when i run that against the DB in the Query Analyzer it runs just fine and returns the records I need it too.

    If I run it in my code I get this error:
    ex.Message "'.' is an invalid name because it contains a NULL character."

    Any ideas why I can not run that in code.
    Thanks in advance
    Last edited by OUSoonerFan; Mar 9th, 2004 at 07:22 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    can anyone assist wih this..or have any ideas....

  3. #3
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    This is a string variable?
    That you pass to ADO?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    Yes it is

  5. #5
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    I ask the DBA he said to look at your () with all the "or" statement!
    Hope it helps
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    Well If i do this also it errors the same error.

    Select * From Contact1 as c1 inner join Contact2 as c2 On c1.U_STATE = 'CA'

    That returns the same error...

  7. #7
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    Is it an sql error?
    What sql are you running and what ADO?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    I amd running SQL Server 2000. Here is the code


    VB Code:
    1. Private Function PullGMRecords(ByVal sFilter As String, ByRef sGMConnection As SqlClient.SqlConnection) As DataSet
    2.         PullGMRecords = New DataSet
    3.         Dim GMCommand As New SqlClient.SqlCommand
    4.  
    5.         If sGMConnection.State = ConnectionState.Closed Then
    6.             sGMConnection.Open()
    7.         End If
    8.         Dim GMAdapter As New SqlClient.SqlDataAdapter(GMCommand)
    9.         Try
    10.             GMCommand = sGMConnection.CreateCommand
    11.             GMCommand.CommandText = sFilter
    12.             GMCommand.CommandTimeout = 180
    13.             GMAdapter.SelectCommand = GMCommand
    14.             GMAdapter.Fill(PullGMRecords, "Contact1")
    15.             sGMConnection.Close()
    16.         Catch ex As Exception
    17.             Showdebug("An error occured trying to pull GM Records." & vbCrLf & ex.Message, "PullGMRecords", "FlipperReadError")
    18.         End Try
    19.         Return PullGMRecords
    20.     End Function

    The statement is what is being sent along with a ref to the connection. Like i said wierd thing is If I run the select statement in the query analyzer it runs fine...but when i try to fill the dataset using the query it give the error.

  9. #9
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    See if this will work!
    Select Distinct c1.Accountno, c1.Company, c1.contact, c1.Phone1
    From Contact1 as c1
    Inner join Contact2 as c2 On c1.accountno = c2.accountno
    And c1.U_STATE = 'CA'
    AND c1.U_STATE Not in ('WI','UT','TX','TN','PR')


    You most add the rest of the states
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    Same error...works fine in SQL Query analyzer...craps out in the code

  11. #11
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Does it return a NULL in sql?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    No in the analyzer i get 3 records.

  13. #13
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Look on the 9th line in your original post:
    c1.U_STATE IS NULL) OR (c1.U_STATE <> '' OR c1.U_STATE IS NULL) OR (c1.U_STATE <> 'OH' OR
    You don't have a state listed in the first comparison after the first OR.
    Maybe that's what you want, but it stands out from the rest of your code.

  14. #14
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    Good eye
    I should have seen that!


    Does it work with the state inserted in the code?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    nope same error

  16. #16
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Try renaming your dataset. Maybe the function is confused because the dataset and function have the same name.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    tried that.....

  18. #18
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Can you post the error number?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  19. #19
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    That's a confusing SQL statement. I'm not sure you need to check for Null more than once, but it's hard to get a handle on it.
    The error you posted has '.' as the problem. Is there a spot in the sql in the code where that character's inadvertently orphaned? Or, is there a limit on the length of an Sql statement (don't know myself).
    Check sFilter before it's executed to make sure it's the correct text.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    I have tried that...here is the thing.I am pulling everything after the "On" From a Field in a database. Basically you build a filter in a CRM called goldmine . Then my software allows you to use the statement that was made in goldmine to pull records into my software. Instead of having to build another filter in my software. As far as I can see, I can not find an orphen '.' The wierd thing to me is if I copy the statement from sFilter and use it in the query anaylzer of SQL 2000 server against the database It runs fine. So why would it not run fine in code. I am literally copy..> paste intot the analyzer.

  21. #21
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Well, you got me. As a test, try pasting the SQL into your function and use that instead of sFilter. If it runs then, the problem must occur in goldmine, whatever that is.
    You could run sFilter through a parsing function to remove any NULL characters, maybe.

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    Ok here is a wierd thing.
    If i do this.
    VB Code:
    1. FilterAfter = "Select Distinct c1.Accountno, c1.Company, c1.contact, c1.Phone1  From Contact1 as c1 Inner join Contact2 as c2 On c1.accountno = c2.accountno And  " & FilterAfter

    with FilterAfter being a string variable holding the rest of the statement. I get the error. But IF I do this.

    VB Code:
    1. FilterAfter = "Select Distinct c1.Accountno, c1.Company, c1.contact, c1.Phone1  From Contact1 as c1 Inner join Contact2 as c2 On c1.accountno = c2.accountno And  c1.U_State = 'CA'"
    It will work.
    Now the c1.U_State = 'CA' is the same as the filterafter it is just not being held inside the variable. Any ideas on why this would do that?

  23. #23
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    In your first example, you're giving FilterAfter a value & concatenating it w/itself. Not sure what order the operations occur, but if FilterAfter has no value before you're first statement, or empty string, that's what you're concatenating to the SELECT part of the statement. If FilterAfter does have a value, you may be overwriting it.
    Try FilterAfter = <Select part>
    FilterAfter += <rest of statement>

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    nope...same error when i tried that. How would I parse it from all NULL Chars....not spaces but anything null.

  25. #25
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Replace() any NULLs with an empty string. Actually, not sure Replace() works with NULL, but you could try it. Or loop through character by character, getting rid of NULLs. You may need Edneiss or Pirate

  26. #26
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353
    Did you get this?
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    ya i tried that over the weekend. Still showing the same error.

  28. #28
    Hyperactive Member mudfish's Avatar
    Join Date
    Feb 2004
    Location
    Chit Chat
    Posts
    353

    The only thing I can think of is a NULL is being return from sql and in VB6 you would get an error number 94 ( I think that the number ) putting the NULL value in the record set!
    Mudfish AKA Bowfin
    I can spell "If" all day right, just a coder!


    "Always do sober what you said you'd do drunk. That will teach you to keep your mouth shut." -- Ernest Hemingway

    Member of the ECCC

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    Ok found the problem....in the part of the SQL statement being sent from goldmine. It is giving me some trailing null chars. not spaces but chars. the trim is not working to remove them. How can I remove all the null characters out of the string?

  30. #30
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    have you tried converting your apostrophes into another character? That caused me a day's work of debugging once myself.

    an apostrophe causes problems in DB queries.

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    I got it. I basically split the SQL String into a char array and then looked for the asc(0). Which is a null value. Using the IEnumerator. It seems to work fine now. The apostrophies can not be changed when exceuting the SQL Query Statement. They are what tells the SQL Server that it is a string.

    Thanks for everyones help.
    Any time I have a problem you guys have never let me down. =)

  32. #32
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Yay, way to go!
    Not to toot my own horn, but I did question the return from goldmine, and suggested parsing it for NULL (although didn't give you a good example of how to do it, sorry).
    That was a really puzzling problem.

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    yes you did....after looking back at post over the weekend I realized the parsing for Null that you suggested was the only thing I have not tried.....so much help was offered i missed that one...lol...

    Thanks Again

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